我想读取复选框的状态表单Tkinter lib。 我尝试了两个方法get()和state(),但没有一个返回正确的数据,下面是代码。 当您按下启动按钮时,程序将从复选框中读取数据并执行此过程
import tkinter as tk
def start():
res = rs.state()
# res = rs.get()
print("the value of checkbox is: ", res)
win = tk.Tk()
# global rs
rs = tk.IntVar()
picheck = tk.Checkbutton(win, text="PI chart", variable=rs)
button = tk.Button(win, text="Start", command=start, pady=15, padx=25, bg='green', fg='white', font=35)
picheck.pack()
button.pack()
win.mainloop()
然后我想它可能与调用函数中的数据有关,所以我将其设置为全局的,但不起作用。此时,get()函数只返回零,state()给出以下错误
AttributeError: 'IntVar' object has no attribute 'state'
目前没有回答
相关问题 更多 >
编程相关推荐