【发布时间】:2019-04-22 20:54:29
【问题描述】:
你能帮帮我吗?我正在尝试创建跟随函数的按钮,然后在文本框中输出,这是我目前的代码:
root = Tk()
menu = Menu(root)
root.config(menu=menu)
filemenu = Menu(menu)
root.filemenu = filedialog.askopenfilename()
menu.add_cascade(label="New Measures", menu=newMeasures)
filemenu.add_command(label="See all measures", command=getMeasures)
filemenu.add_command(label="See the total rain", command=totalRain)
filemenu.add_command(label="See the total electricity", command=totalElectricity)
filemenu.add_command(label="See the measures for a date", command=find_date)
#filemenu.add_command(label="Change the data for a date", command=edit_date)
filemenu.add_separator()
filemenu.add_command(label="Exit", command=root.destroy)
但它什么也没做 - 它只是显示一个空的 tk() 框
【问题讨论】:
-
您的代码不会创建任何文本框并引发
NameError。 -
1.您没有在此代码中使用文本框。 2.
root.filemenu是一个糟糕的变量名称,老实说,我什至不认为root.filemenu会起作用。 3. 您拥有所有这些标签,每个标签都有不同的命令,但您没有显示这些功能在做什么,因此无法知道您的代码有什么问题。 4. 您还需要包含您正在使用的导入。