Python tkinter import error

2019-09-21 20:27发布

from tkinter import *
from tkinter import messagebox

root= Tk()
root.mainloop()

Error:

...Traceback (most recent call last): File "C:\Users\Lee\Desktop\Python projects\tkinter.py", line 1, in import tkinter as Tk File "C:\Users\Lee\Desktop\Python projects\tkinter.py", line 2, in from tkinter import messagebox ImportError: cannot import name 'messagebox'

[Finished in 25.248s] I have no idea why messagebox won't import?

1条回答
戒情不戒烟
2楼-- · 2019-09-21 20:59

You named your file tkinter.py, so when you import tkinter, it's importing that file rather than the real tkinter module.

Rename your file to just about anything else.

查看更多
登录 后发表回答