samedi 14 mars 2015

tkinter variable does not change when changing Checkbutton state

I have a Window wich opens another window askig for the settings. But the BooleanVar I use to get the Checkbutton's state doesn't change. It does however when I call the settingswindow strait from the code without the other window.


This is the minimal code to get the problem: from tkinter import *



class MainWindow():

def __init__(self, master):

self.root = master
SettingsWindow()
self.root.mainloop()

class SettingsWindow():

def __init__(self):
rootSettings = Tk()

self.rebuild = BooleanVar()
chkRebuild = Checkbutton(rootSettings, text="rebuild", variable=self.rebuild, command=self.testFunc)
chkRebuild.pack()

rootSettings.mainloop()

def testFunc(self):
print(self.rebuild.get())

root = Tk()
mainWindow = MainWindow(root)


The output is always 0 when clicking on the checkbutton, evenso the output of BooleanVar is True or False.


What is the difference in calling SettingsWindow() from insite a class or outside? At least I think that is the reason it is not working.


I am using Pyhton3 in case there is a difference.





Aucun commentaire:

Enregistrer un commentaire