当我试试这个,
archivist_dates=[
"Thur,19th of October",
"Fri,20th of October",
"Sat,21th of October",
"Sun,22th of October",
"Mon,23th of October",
"Tue,24th of October",
"Wed,25th of October",
"Latest"]# the list of dates to be selected by the users
variable=StringVar()
variable.set(archivist_dates[0])
list_menu=OptionMenu(archivist_gui,variable,*archivist_dates)
list_menu.grid(row=2,column=2)
archivist_buttons=Frame(archivist_gui)
extract_button=Radiobutton(archivist_buttons,variable,text='Extract news
from archive', value=1, font=('Times',24),command=extracts)
display_button=Radiobutton(archivist_buttons,variable,text='Display news
extracted',value=2,font=('Times',24),command=htmlgenerator)
archive_button=Radiobutton(archivist_buttons,variable,text='Archive the
latest news',value=3,font=('Tikmes',24),command=download)
有一个错误声明显示如下:
_cnfmerge:由于以下原因导致回退:'StringVar'对象不可迭代Traceback(最近调用最后一次):文件“/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter/init.py”,第103行,在_cnfmerge中cnf.update(c)TypeError:'StringVar'对象不可迭代在处理上述异常期间,发生了另一个异常:Traceback(最近一次调用last):File“/ Volumes / study / en01 / ifb104 / ass2 / InternetArchive / news_archivist.py“,第798行,在extract_button = Radiobutton(archivist_buttons,变量,text ='从档案中提取新闻',值= 1,字体=('时代',24),命令=摘要)文件” /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/tkinter/init.py“,第2978行,在init Widget.init中(self,master,'radiobutton',cnf,kw)文件”/ Library / Frameworks / Python.framework / Versions / 3.6 / lib / python3.6 / tkinter / init.py“,第2284行,在init cnf = _cnfmerge((cnf,kw))文件”/Library/Frameworks/Python.framework /Versions/3.6/lib/python3.6/tkinter/init.py“,第106行,在_cnfmerge中k,v in c.items():AttributeError:'StringVar'对象没有属性'items'
有人能解释错误并帮我解决问题吗?
1 回答
问题出在这里:
您正在错误地分配
variable
,Radiobutton
正在查找不存在的variable['items']
,因为StringVar()
没有名为'items'
的属性 .相反,您应该将
StringVar()
指定为variable=variable
. 意味着完整的呼叫将是: