Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
272 views
in Technique[技术] by (71.8m points)

python - AttributeError: 'IntVar' object has no attribute 'state'

I want to read the status of a Checkbox form Tkinter lib. I tried two methods get() and state() but non of them returned the proper data, below is the code. when you press the Start button then the program should read data from checkbox and do the process.

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()

then I thought maybe it relates to calling the data from function so I made it global but did not work. At this point, the get() function only returns ZERO and the state() gives me the below error.

AttributeError: 'IntVar' object has no attribute 'state'


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...