Tkinter 中的“root.mainloop()”导致 AttributeError

Con*_*ews 2 python tkinter attributeerror

在我的 python 代码中,该root.mainloop()行导致错误:

AttributeError: '_tkinter.tkapp' object has no attribute 'mainLoop'

我在 Mac 上,我的代码是:

from tkinter import *
root = Tk()
myLabel1 = Label(root, text = 'My First GUI')
myLabel1.pack()
root.mainLoop()
Run Code Online (Sandbox Code Playgroud)

Reb*_*que 6

你应该更换:

root.mainLoop()
Run Code Online (Sandbox Code Playgroud)

root.mainloop()
Run Code Online (Sandbox Code Playgroud)

全部为小写字母。