In this article we want to learn How to Install Tkinter in Windows & Linux, so first of all let’s talk about TKinter.
What is TKinter ?
Tkinter is built in graphical user interface (GUI) library for Python programming language. It provides an easy way for creating graphical user interfaces (GUIs) with Python, In TKinter you can use Tk GUI toolkit. Tkinter provides different set of widgets like buttons, text boxes, etc, and tools to create and manage windows, dialogs and other GUI elements. Tkinter is easy to use and widely used for creating desktop applications in Python.
How to Install Tkinter in Windows & Linux ?
Windows:
- Tkinter is preinstalled in Python for Windows, no separate installation is required.
- To check if Tkinter is installed, run the following command in the Python terminal: import tkinter
- If there’s no error, Tkinter is installed.
Linux:
- Tkinter is preinstalled in Python for Linux, no separate installation is required.
- To check if Tkinter is installed, run the following command in the Python terminal: import tkinter
- If there’s no error, Tkinter is installed.
- If Tkinter is not installed, you can install it using the package manager of your Linux distribution. E.g., for Ubuntu, you can use the following command: sudo apt-get install python3-tk
Which Kind of GUI Apps I Can Make with TKinter ?
With Tkinter you can create different types of GUI based applications such as:
- Desktop applications with a graphical user interface.
- Multi Window applications.
- Database driven applications.
- Applications with simple dialogs and pop-up windows.
- Applications with charts, graphs and images.
- Custom widgets and controls for GUI.
Tkinter provides a lot of GUI building blocks, and it is one of the best library for building simple to complex GUI applications.
This is an example of a simple Tkinter application that displays greeting message:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
import tkinter as tk def greet(): label.config(text="Hello, Tkinter") root = tk.Tk() root.title("Simple Tkinter App") label = tk.Label(root, text="Welcome to codeloop.org") label.pack() greet_button = tk.Button(root, text="Greet", command=greet) greet_button.pack() root.mainloop() |
Run the code and this will be the result
Tkinter Questions: FAQs
How to install Tkinter in Python on Linux?
Tkinter is typically included with Python installations on Linux. But if it’s not available, you can install it using your package manager. For example, on Debian-based systems like Ubuntu, you can use the following command:
1 |
sudo apt-get install python3-tk |
How to install tk on Windows?
Tkinter is included with standard Python installations on Windows, so you don’t need to install it separately. If you’re using a Python distribution like Anaconda, Tkinter is also included by default.
How to install Python GUI in Ubuntu?
For installing Python GUI toolkit like Tkinter or PyQt on Ubuntu, you typically don’t need to do anything special. Tkinter is included with Python installations, and you can use it out of the box. If you want to use PyQt, you can install it using pip:
1 |
pip install PyQt5 |
Subscribe and Get Free Video Courses & Articles in your Email