В моем скрипте я пытаюсь получить значение из кнопок. Когда я использую метод .get (), он ничего не возвращает. Удивительно, но он прекрасно работает с виджетами Entry, которые находятся в одном окне.
Я не могу понять, в чем проблема.
Вот (упрощенный) скрипт, который я использую.
from tkinter import *
class Interface(Frame):
def __init__(self, window, **kwargs):
super().__init__(**kwargs)
self.gamesList = []
self.library=Library()
self.window=window
self.frame_top=Frame(self.window)
self.frame_top.pack()
self.frame_bot=Frame(self.window)
self.frame_bot.pack()
# For Add Game window #
self.namebox = ""
self.CheckVar1 = StringVar()
self.main_menu()
def main_menu(self):
games_button=Button(self.frame_top, text="Games", command=self.games_window)
games_button.pack()
quit_button = Button(self.frame_top, text="Save and Quit", command=self.quit)
quit_button.pack()
def games_window(self):
self.frame_bot.destroy()
self.frame_bot = Frame(self.window)
self.frame_bot.pack()
players_button = Button(self.frame_bot, text="Add game", command=self.addGame)
players_button.pack()
def addGame(self):
games_window = Tk()
name = Label(games_window, text="Name")
name.pack()
self.namebox=Entry(games_window)
self.namebox.pack()
C1 = Checkbutton(games_window, text="Deck-building", variable=self.CheckVar1, onvalue="Deck-Building",offvalue="")
C1.pack()
validate_button=Button(games_window, text="Validate", command=self.addGameValidate)
validate_button.pack()
def addGameValidate(self):
print(self.CheckVar1.get())
print(self.namebox.get())
def main():
window=Tk()
interface = Interface(window)
interface.mainloop()
interface.destroy()
if __name__ == '__main__':
main()