【发布时间】:2020-09-30 18:13:37
【问题描述】:
我是 tkinter 的新手,我正在尝试从复选按钮获取值选择到我的其他脚本,但在我选择并单击“选择”按钮后,它一直向我显示下面的错误。
这是我的脚本:
from tkinter import *
root = Tk()
options = ["All","Happy","Sad","Angry","Emotional","Disgust","None of above"]
message = Label(root, text ='Select how you feel today: ')
message.pack()
for x in range(len(options)):
choose = Checkbutton(root, text= options[x]).pack(anchor=W)
def selected():
print(choose.get())
result = Button(root, text='Select', width=15, command = selected).pack(pady =6, anchor=SE)
cancel = Button(root, text='Cancel', width=15, command = root.destroy).pack(pady=6,anchor=SE)
root.mainloop()
File "C:\Users\Desktop\Python\temp.py", line 22, in selected
print(choose.get())
AttributeError: 'NoneType' object has no attribute 'get'
我需要如何更改我的代码,以便我可以从我的复选框中获取我勾选的值?
【问题讨论】: