首页 > 解决方案 > Tkinter 中的 'root.mainloop()' 导致 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()

标签: pythontkinterattributeerror

解决方案


你应该更换:

root.mainLoop()

root.mainloop()

全部用小写字母。


推荐阅读