root.config属性错误Python / Tkinter

时间:2018-03-19 13:54:59

标签: python python-3.x python-2.7 tkinter

所以当我尝试运行我的代码时,我一直遇到这个问题。我是编程的新手,所以我不确定该怎么做。 这是代码:

from Tkinter import *

def donothing():
    print "Ok ok i wont.."

root = Tk()

menu = Menu(root)
root.conifig(menu=menu)

submenu = Menu(menu)
menu.add_cascade(label="File", menu=subemenu)
submenu.add_command(label="New project...", command=donothing)
submenu.add_command(label="save", command=donothing)
submenu.add_separator()
submenu.add_command(label="Exit", command=donothing)

editmenu = Menu(menu)
menu.add_cascade(label="Edit", menu=editmenu)
editmenu.add_command(label="Redo", command=donothing)


root.mainloop()

这是问题所在:

Traceback (most recent call last):
  File "gui7.py", line 9, in <module>
    root.conifig(menu=menu)
  File 


"/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/li 
    b-tk/Tkinter.py", line 1898, in __getattr__
        return getattr(self.tk, attr)
    AttributeError: conifig

1 个答案:

答案 0 :(得分:0)

Tkinter没有属性conifig,而是config可以检查tkinter documentation以检查tkinter的其他属性。

from Tkinter import *

def donothing():
  print "Ok ok i wont.."

root = Tk()

menu = Menu(root)
root.config(menu=menu)

submenu = Menu(menu)
menu.add_cascade(label="File", menu=submenu)
submenu.add_command(label="New project...", command=donothing)
submenu.add_command(label="save", command=donothing)
submenu.add_separator()
submenu.add_command(label="Exit", command=donothing)

editmenu = Menu(menu)
menu.add_cascade(label="Edit", menu=editmenu)
editmenu.add_command(label="Redo", command=donothing)


root.mainloop()