All tutorials simply import tkinter
,
I am wondering, though, why not import _tkinter
? If my understanding is correct, _tkinter
is the actual library in cpython and tkinter
is the interface or API.
I am simply trying to grasp the paradigm as I read through some of the tkinter source code. It seems there is some python black magic afoot.
Build A Paint Program With TKinter and Python The only difference between Tkinter and tkinter is that Tkinter was initially used with Python 2 and tkinter is used for working with Python 3 or later versions.
Tkinter actually comes along when we install Python. While installing Python, we need to check the td/tk and IDLE checkbox. This will install the tkinter and we need not install it separately. However, if we missed installing Tkinter while installing Python, we can do it later using the pip command.
Using import tkinter as tk It comes with all the modules defined in tkinter. However, to save the major typing efforts, we import the tkinter library with some acronym further that can be used to create an instance of widgets. Thus, the application structures become more aesthetical by using the import tkinter as tk.
Python when combined with Tkinter provides a fast and easy way to create GUI applications. Tkinter provides a powerful object-oriented interface to the Tk GUI toolkit. Creating a GUI application using Tkinter is an easy task. All you need to do is perform the following steps − Import the Tkinter module.
_tkinter
is a C-based module that wraps an internal tcl/tk interpreter. When you import it, and it only, you get access to this interpreter but you do not get access to any of the python classes.
You certainly can import _tkinter
, but then you would have to recreate all of the python interfaces to the tcl/tk functions.
In python "_" marks a variable is intended for internal use
This convention is defined in PEP 8, but isn't enforced by Python
You shouldn't import class/modules/variables starting with "_" due to that nature, the developer should allow a property/setter methods to access those attributes..
For python2 use "Tkinter"
For python3 use "tkinter"
http://pep8.org/#descriptive-naming-styles
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With