Имеем баг: при нажатие на "Вот эта кнопка" кнопку ткинтер не реагирует, но при нажатие на кнопку Add родительского окна, он тут же выводит, то, что должно выводится при нажатие на "Вот эта кнопка" кнопку. Я понятия не имею как это получилось...
from tkinter import *
class Notificator:
def __init__(self):
self.root = Tk()
self.root.configure(width=320, height=200)
self.root.title('Notificator')
self.words = ['opposition = оппозиция', 'crossroads = перекрёстки', 'game = игра']
self.iterator = iter(self.words)
self.main()
def iter(self):
try:
self.next_word = next(self.iterator)
except StopIteration:
self.iterator = iter(self.words)
self.next_word = next(self.iterator)
return self.next_word
def spliter(self, string):
self.object = str(string)
self.two_words = self.object.split('=')
return self.two_words
def word_changer(self):
self.worder = self.spliter(self.iter())
self.Translate.configure(text='Russian: ' + str(self.worder[1]), font=('family', 20))
self.Word.config(text=('English: ' + str(self.worder[0])), font=('family', 20))
self.root.update()
def add_starter(self):
self.root.destroy()
add = AddWord()
def main(self):
self.worder = self.spliter(self.iter())
self.OK = Button(self.root, width=8, height=3, text='Exit', font=('family', 10), command=lambda: self.root.destroy())
self.OK.place(x=161, y=116)
self.Word = Label(self.root, text=('English: ' + str(self.worder[0])), font=('family', 20))
self.Word.place(x=31, y=34)
self.Translate = Label(self.root, text='Russian: ' + str(self.worder[1]), font=('family', 20))
self.Translate.place(x=10, y=70)
self.next = Button(self.root, width=8, height=3, text='Next', command=self.word_changer, font=('family', 10)).place(x=50, y=116)
self.add = Button(self.root, width=4, height=3, text='Add', command=self.add_starter)
self.add.place(x=282, y=0)
self.root.mainloop()
class AddWord:
def __init__(self):
self.two = Tk()
self.two.config(height=200, width=400)
self.two.title('Add a word')
self.main()
def main(self):
self.ButtOK = Button(self.two, width=8, height=3, text='Exit', command=self.back_to_main)
self.ButtOK.place(x=120, y=100)
self.stringer = StringVar()
self.stringer2 = StringVar()
self.Enttry = Entry(self.two, textvariable=self.stringer).place(x=150, y=20)
self.Enttry1 = Entry(self.two, textvariable=self.stringer2).place(x=150, y=60)
self.ButtOK = Button(self.two, width=8, height=3, text='Вот эта кнопка', command=self.adddereder()).place(x=220, y=100)
self.Label1 = Label(self.two, text='English:', font=('arial', 20)).place(x=40, y=9)
self.Label2 = Label(self.two, text='Russin:', font=('arial', 20)).place(x=40, y=47)
self.two.mainloop()
def adddereder(self):
print('Выводит это сообщение при нажатие на Add главного окна, а должен при нажатии на дочернем ')
def back_to_main(self):
self.two.destroy()
Main_window = Notificator()
Main_window = Notificator()