【问题标题】:Output-ing functions into a text box, tkinter将函数输出到文本框,tkinter
【发布时间】: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. 您还需要包含您正在使用的导入。

标签: python tkinter sqlite


【解决方案1】:

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

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

您创建的菜单称为“filemenu”。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-02
    • 2023-02-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多