- What is Tkinter used for and how to install it?
- What is Tkinter Used For
- How to Use Tkinter
- How to Download Tkinter for Python 3
- How to Install Tkinter
- Install Tkinter
- Install Tkinter on Windows
- Install Tkinter on Linux
- Install Tkinter on Mac Operating System
- Install Tkinter in Pycharm
- Как установить Tkinter в Python для Windows
- Установка Tkinter в Windows
- Pip Install Tkinter
- Pre-requisites
- Python
- Pip
- Check for Built-in Tkinter Package
- Installing Tkinter with Pip
- Testing the Tkinter Package
- Conclusion
- About the author
- Abdul Mannan
What is Tkinter used for and how to install it?
Tkinter is the de facto way in Python to create Graphical User interfaces (GUIs) and is included in all standard Python Distributions. In fact, it’s the only framework built into the Python standard library.
This Python framework provides an interface to the Tk toolkit and works as a thin object-oriented layer on top of Tk. The Tk toolkit is a cross-platform collection of ‘graphical control elements’, aka widgets, for building application interfaces.
If you want to take advantage of the latest version of Tkinter, you’ll need to install a version of Python that supports Tcl/Tk 8.5 or greater. This will provide you with the Ttk (Tile extension integrated into Tk), which is required in order to run the current Tk widget set.
Warning: If you’re working on a system that comes with Python pre-installed, you may need to upgrade it to at least Python 3.7, which includes everything you need to run Tk out of the box.
To verify the Tcl version on your computer, enter:
$ tclsh % info patchlevel 8.6.8
To open a Tcl/Tk shell and verify that it is working, enter a command similar to the following:
A popup window titled wish8.6 will appear.
To verify that Tkinter is properly installed, enter:
A popup window that states the Tcl/tk version should appear.
What is Tkinter Used For
This framework provides Python users with a simple way to create GUI elements using the widgets found in the Tk toolkit. Tk widgets can be used to construct buttons, menus, data fields, etc. in a Python application. Once created, these graphical elements can be associated with or interact with features, functionality, methods, data or even other widgets.
For example, a button widget can accept mouse clicks, and can also be programmed to perform some kind of action, such as exiting the application.
How to Use Tkinter
In the following example, Tkinter creates a Tk application frame and a button widget that exits the application when clicked.
from tkinter import * tk = Tk() frame = Frame(tk, borderwidth=2) frame.pack(fill=BOTH, expand=1) label = Label(frame, text="Button Example") label.pack(fill=X, expand=1) button = Button(frame, text="Exit", command=tk.destroy) button.pack(side=BOTTOM) tk.mainloop()
How to Download Tkinter for Python 3
As previously stated, the best way to get the latest version of Tkinter is to install Python 3.7 or later. But Tkinter can also be downloaded and installed as part of any standard Python 3 installation.
How to Install Tkinter
If you are using a Python 3 version prior to Python 3.7, or a non-standard version of Python 3 that does not include Tkinter, do the following:
$ sudo apt-get install python3-tk
On a Windows or Mac System:
The simplest and easiest method to install Tkinter, is to either:
Install Tkinter
- Install Tkinter on Windows
- Install Tkinter on Linux
- Install Tkinter on Mac Operating System
- Install Tkinter in Pycharm
This tutorial will demonstrate how to install Tkinter on multiple platforms. Every platform has individual commands to install Tkinter in Python.
Install Tkinter on Windows
Tkinter offers multiple GUI libraries to develop GUI applications. The Tkinter is one of the popular libraries to build GUI system interfaces.
To install Tkinter, we have to install Python; if it is already installed, we can move on to install Tkinter. When we start the installation of Python, we can check td or tk and IDLE Tkinter during installation.
This way, this Tkinter will come along with Python packages, and we do not need to install it separately. However, if we lose installing Tkinter during the installation of Python, we can do it later using the pip command.
We can confirm the Python version using this command.
Pip ’s version is checked using this command.
Now we are ready to install Tkinter.
Now we can use the tkinter library. To confirm the tkinter library is installed, write the code in the shell.
import tkinter tkinter._test()
If you are an Anaconda user, you can use the following command.
conda install -c anaconda tk
Install Tkinter on Linux
There are different variants of the Linux operating system. This section will learn how to install Tkinter in multiple variants.
Use this command if you’re using a Debian-based Linux operating system.
# python2 user sudo apt-get install python-tk
# python3 user sudo apt-get install python3-tk
Use this command if you’re using one of these: RHEL, CentOS, Oracle Linux.
sudo yum install -y tkinter tk-devel
The Fedora-based Linux operating system uses this command.
Use this command to confirm the tkinter library is installed successfully.
Install Tkinter on Mac Operating System
There are two ways to install the tkinter library in MacOS. The Mac user will follow these steps.
Run the below command to check that python3 is installed.
Run the below command to check that pip3 is installed.
If your pip is outdated, please upgrade your pip using the below command.
We will use pip3 as the first method. Write the following command to install Tkinter.
The second method needs a setup.py file to install the Tkinter.
We have to download the latest version of Tkinter in python3 using this command.
curl https://files.pythonhosted.org/packages/a0/81/ 742b342fd642e672fbedecde725ba44db44e800dc4c936216c3c6729885a/tk-0.1.0.tar.gz > tk.tar.gz
Write the following command to extract the downloaded package.
Go to the extracted folder and run this command.
To ensure the tkinter library is installed, run this code in the Python terminal.
Install Tkinter in Pycharm
The installation process is very simple in Pycharm IDLE. Pycharm IDLE is more convenient for users.
There is an interface to install the tkinter library without running a command.
Go to File>Settings>Project>Python Interpreter and click the + button, search tk , and click the Install Package button. You can select the specific version.
Click here to read more about Tkinter.
Hello! I am Salman Bin Mehmood(Baum), a software developer and I help organizations, address complex problems. My expertise lies within back-end, data science and machine learning. I am a lifelong learner, currently working on metaverse, and enrolled in a course building an AI application with python. I love solving problems and developing bug-free software for people. I write content related to python and hot Technologies.
Как установить Tkinter в Python для Windows
Tkinter – это стандартная библиотека Python, которая используется для приложения с графическим интерфейсом. Tkinter с Python предлагает простой и быстрый способ создания приложений с графическим интерфейсом.
Tk GUI работает на основе объектно-ориентированного подхода, что делает его мощной библиотекой. Tkinter широко доступен для всех операционных систем. Он предварительно установлен в Python. Для работы с Tkinter мы должны установить Python. В этом руководстве мы узнаем, как установить Tkinter в Python для Windows.
Чтобы создать удобное приложение с графическим интерфейсом пользователя, вы должны иметь базовые знания языка программирования Python.
Установка Tkinter в Windows
Tkinter поставляется с установщиком Python. Нам просто нужно установить Python с www.python.org, Tkinter идет вместе с Python. Устанавливать отдельно не нужно. Установите флажок tcl / tk и IDE.
Чтобы проверить Tkinter, нам просто нужно импортировать его в текстовый редактор или IDE.
Теперь мы можем получить доступ к его функциям для создания виджета. Давайте разберемся в следующем.
from tkinter import * root = Tk() # Code to add widget will go here…….. w = Label(root, width = "40", height = "15") w.pack() root.mainloop()
Все элементы будут размещены в этом окне Tkinter.
Pip Install Tkinter
The “Tkinter” package/library of python is used to develop the Graphical User Interfaces of python-based applications with great ease and control. What most people don’t realize is that the Tkinter package comes pre-installed in python 3.7 or higher, and if that is not the case, then it can be separately downloaded using the Pip commands.
Pre-requisites
There are a few pre-reqs for installing and using the Tkinter Package, and these pre-reqs include:
Python
Python must be installed in the user’s PC to not only install Tkinter but also to use it. To verify if python is installed on the PC or not, run the following command inside a Command Prompt or any other terminal:
The above command will produce the following results if python is installed:
Pip
After python, ensure that pip is also installed on the PC by using the following command inside the Command Prompt or any other terminal:
The output confirms that pip is installed on the user’s PC.
Check for Built-in Tkinter Package
As mentioned above, the Tkinter package also comes pre-installed with python 3.7 and higher. This essentially means that the user might not need to explicitly install the Tkinter package as it may already be installed on his machine. To verify this, run the following command inside the Command Prompt:
If the tkinter package is already installed, then the above command will result in the following output:
If the output is an error, then that means that the tkinter package is not pre-installed on your PC.
Installing Tkinter with Pip
Once you have made sure that you have all the prerequisites installed and also that there is no built-in tkinter with your python package, simply install the Tkinter using the following pip command:
Alternatively, you can also use the following command:
Both of the above commands will download and install the Tkinter package on your PC:
Testing the Tkinter Package
To test that the tkinter package has been successfully installed and is working, simply open up a python shell, by typing in “python” in a command prompt window:
After that, import the tkinter package and launch a new frame using the following lines:
After that, the following window will open up:
The window contains a demo GUI from the tkinter package, which contains two buttons, “Click me!” and “QUIT,” and two statements that display the version of the TK or the TCL package. The current version installed is the “Tcl 8.6”
Conclusion
The “pip install tkinter” command is used to install the tkinter package in python, a Graphical User Interface builder package that provides many features to the developer. However, this Tkinter package, also known as Tcl or TK package, comes as a built-in module with python 3.7 and higher. Therefore, the user might not necessarily need to install the tkinter package separately. This post has pictorially represented the purpose and the usage for the “pip install tkinter” command.
About the author
Abdul Mannan
I am curious about technology and writing and exploring it is my passion. I am interested in learning new skills and improving my knowledge and I hold a bachelor’s degree in computer science.