将函数输出到文本框中,tkin

2024-05-02 15:24:29 发布

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

你能帮帮我吗?我正在尝试创建跟随函数的按钮,然后在文本框中输出,到目前为止,这是我的代码:

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


Tags: the函数addfordaterootlabelcommand
1条回答
网友
1楼 · 发布于 2024-05-02 15:24:29

当您将第一个下拉按钮添加到菜单时,您正试图将其放入不存在的“newMeasures”菜单中

menu.add_cascade(label="New Measures", menu=newMeasures)

您创建的菜单称为“文件菜单”

menu.add_cascade(label="New Measures", menu=filemenu)

相关问题 更多 >