Tkinter , 'module' object has no attribute 'Frame'
install tkinter python3
tkinter python 3
i write a hello world app in tkinter python, but i recive next message: 'module' object has no attribute 'Frame'
import _tkinter as tk
here is the error
class Application(tk.Frame): def __init__(self, master=None): tk.Frame.__init__(self, master) self.pack() self.createWidgets() def createWidgets(self): self.hi_there = tk.Button(self) self.hi_there["text"] = "Hello World\n(click me)" self.hi_there["command"] = self.say_hi self.hi_there.pack(side="top") self.QUIT = tk.Button(self, text="QUIT", fg="red", command=root.destroy) self.QUIT.pack(side="bottom") def say_hi(self): print("hi there, everyone!") root = tk.Tk() app = Application(master=root) app.mainloop()
why this are happening?
You should use
tkinter if you use Python 3.x), not
import Tkinter as tk
According to Tkinter module documentation:
... The Tk interface is located in a binary module named
_tkinter. This module contains the low-level interface to Tk, and should never be used directly by application programmers.
TkInter, Tkinter is Python's de-facto standard GUI (Graphical User Interface) package. It is a thin object-oriented layer on top of Tcl/Tk. Tkinter is not the only GuiProgramming toolkit for Python. It is however the most commonly used one. Tkinter is Python's de-facto standard GUI (Graphical User Interface) package. It is a thin object-oriented layer on top of Tcl/Tk. Tkinter is not the only GuiProgramming toolkit for Python. It is however the most commonly used one.
Don't call your file as
tkinter.py, rename if it is necessary.
Python GUI Programming With Tkinter – Real Python, Python GUI Programming with Tkinter: Develop Responsive and Powerful GUI Applications with Tkinter Tkinter (GUI Programming) Tkinter is a graphical user interface (GUI) module for Python, you can make desktop apps with Python. You can make windows, buttons, show text and images amongst other things. Tk and Tkinter apps can run on most Unix platforms.
The solution here is to use the correct syntax for the associated Python version.
Tkinter >> Python 2.x
tkinter >> Python 3.x
Despite this, I had errors because I had called my file tkinter.py, and was presented with the error:
module 'tkinter' has no attribute 'Frame'
Once I'd renamed my file to something else entirely, in my case I chose tk-testing.py it was fine in both Python 2.x and Python 3.x, whilst using the correct naming conventions above.
import Tkinter as tk
import Tkinter as tk
Python - GUI Programming (Tkinter), Tkinter GUI Application Development Cookbook: A Practical Solution to Your GUI Development Problems with Python and Tkinter Python has a lot of GUI frameworks, but Tkinter is the only framework that’s built into the Python standard library. Tkinter has several strengths. It’s cross-platform, so the same code works on Windows, macOS, and Linux.
Python GUI - tkinter, Tkinter GUI Application Development Blueprints, Second Edition: Build Nine Projects by Working with Widgets, Geometry Management, Event Handling, and More, 2nd Edition Tkinter is actually an inbuilt Python module used to create simple GUI apps. It is the most commonly used module for GUI apps in the Python. You don’t need to worry about installation of the Tkinter module as it comes with Python default. I am going to use Python 3.6 version for this tutorial.
Tkinter Course, Tkinter GUI Programming by Example: Learn to Create Modern GUIs Using Tkinter by Building Real-world Projects in Python An Introduction To Tkinter This is an incomplete draft version, last updated in November 2005. You can find an earlier but more complete version in the PythonWare library (dead link). Note: This is the source document used to generate the PythonWare version of An Introduction To Tkinter.
An Introduction To Tkinter, Tkinter is the standard GUI library for Python. Python when combined with Tkinter provides a fast and easy way to create GUI applications. Tkinter provides a Tkinter in Python comes with a lot of good widgets. Widgets are standard graphical user interface (GUI) elements, like different kinds of buttons and menus. Most of the Tkinter widgets are given here.
- I'm curious. How did you conclude that
import _tkinter as tkwas correct? Did you read it somewhere?
- That was the reason why my code was not working ... Thanks a million ...
- Thanks for pointing out that the file itself shouldnt be "tkinter.py" Once I'd renamed my file to something else entirely, in my case I chose tk-testing.py it was fine this solved my problem