-1
我是Tkinter的新手,我希望Checkbutton在檢查時打印一個字符串,並在未選中時打印一個字符串。但是,self.value
總是返回PY_VAR0
是否勾選框。Tkinter上的Checkbutton值不會變化
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()