AttributeError: 'module' object has no attribute 'Tk'

21,876

The problem is that you named your file Tkinter.py. When you do the import, python sees the file and tries to import it instead of the Tkinter library.

Rename your file, and be sure to remove Tkinter.pyc if it exists.

Share:
21,876
Hamza Boughraira
Author by

Hamza Boughraira

Updated on July 09, 2020

Comments

  • Hamza Boughraira
    Hamza Boughraira almost 4 years

    I started to learn GUI developement using the Tkinter python library but I faced a problem with the PyCharm IDE community edition 4.5.2

    My problem is: when I write the code below in the IDLE, it works fine!!! but when I write it using the the PyCharm IDE, this error message appears: AttributeError: 'module' object has no attribute 'Tk' Please help me, I really need help and thank you a lot

    My code:

    import Tkinter
    
    app = Tkinter.Tk()
    app.title("hello world")
    app.minsize(300, 300)
    helloLabel = Tkinter.Label(app, text="hello GUI")
    helloLabel.pack()
    
    app.mainloop()
    

    Note: I'm using Python 2.7.6, OS: Ubuntu 14.04 LTS