AttributeError:“IntVar”对象没有属性“state”

2024-09-30 01:35:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我想读取复选框的状态表单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'


Tags: 数据textget状态buttonresstartwin

热门问题