I'm new to Tkinter, and I'd like the Checkbutton to print a string when it is checked, and a string when it is unchecked. However, self.value
always returns PY_VAR0
whether the box is ticked or not.
from tkinter import *
class New:
def __init__(self, master):
value = StringVar()
self.value = value
frame = Frame(master)
self.c = Checkbutton(
master, text="Expand", variable=value,onvalue="Yes",
offvalue="No",command=self.test)
self.c.pack(side=LEFT)
def test(self):
if self.value == "Yes":
print("Yes!")
if self.value == "No":
print("Not!")
else:
print(self.value)
root = Tk()
app = New(root)
root.mainloop()