I've been attempting to make a simple GUI, and have been working my way through tkinter's various functions. However, I can't for the life of me figure out why this doesn't work.
from tkinter import Tk, Label, Button, Radiobutton,IntVar,StringVar
class TestGUI:
def __init__(self, master):
self.master = master
master.title("Test GUI")
self.mode = IntVar()
self.modetext = StringVar()
self.modetext.set("What does this do?")
self.modelabel = Label(master,textvariable=self.modetext)
self.modelabel.pack()
self.close_button = Button(master, text="Close", command=master.destroy)
self.close_button.pack()
R1 = Radiobutton(master, text="Mode 1", variable=self.mode, value=0, command=self.modeset)
R1.pack()
R2 = Radiobutton(master, text="Mode 2", variable=self.mode, value=1, command=self.modeset)
R2.pack()
R3 = Radiobutton(master, text="Mode 3", variable=self.mode, value=2, command=self.modeset)
R3.pack()
def modeset(self):
self.modetext.set("Mode is " + str(self.mode.get()))
print(self.mode.get())
root = Tk()
T_GUI = TestGUI(root)
root.mainloop()
What it should do, as far as I can tell, is display three radio buttons which set the value of mode, and display "Mode is [mode]" in the label and print the value of mode when one is selected.
Instead, the label is never displayed and choosing a radio button doesn't change the value of mode.
Can anyone give me a clue on what is happening?