Module 'tkinter' has no attribute 'Tk'

前端 未结 5 848
傲寒
傲寒 2020-11-30 15:32

Tkinter doesnt contain any tk attribute.

import tkinter

window = tkinter.Tk()

win.mainloop()

While running this code it gives me an error

相关标签:
5条回答
  • 2020-11-30 16:06

    Did you named your python file tkinter.py or Tkinter.py ? Try to rename it. It may be the cause.

    0 讨论(0)
  • 2020-11-30 16:07

    try 'Tk' instead of 'tk' it worked for me, if you think you are importing wrong,try: import tkinter tkinter._test()

    0 讨论(0)
  • 2020-11-30 16:09

    Try copying the file to the Python path in C drive (in my case)

    And the folder should not contain any other file named Tkinter.py or similar for Code click here

    0 讨论(0)
  • 2020-11-30 16:21

    Python 3.x

    import tkinter
    
    window = tkinter.Tk()
    
    window.mainloop()
    
    0 讨论(0)
  • 2020-11-30 16:27
    import tkinter
    
    raiz= tkinter.Tk()
    
    raiz.mainloop()
    

    remember that the file name cannot be tkinter.py

    0 讨论(0)
提交回复
热议问题