Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»General Articles»How to Install Python Tkinter on Linux

    How to Install Python Tkinter on Linux

    By RahulJanuary 1, 20233 Mins Read

    Tkinter is a Python library that is used to create graphical user interfaces (GUIs). It is a standard Python interface to the Tk GUI toolkit, which is widely used in the Linux operating system. In this tutorial, we will learn how to install Tkinter on a Linux system using either pip or apt-get.

    Advertisement

    Prerequisites

    To install Python’s Tkinter module on a Linux system, you will need to have the following prerequisites installed:

    • Python: Tkinter is a module for Python, so you will need to have Python installed on your system. Most Linux distributions come with Python pre-installed, but if you don’t have it installed you can use your distribution’s package manager to install it.
    • Tcl/Tk: Tkinter is built on top of the Tcl/Tk libraries, so you will need to have these libraries installed in order to use Tkinter. Most Linux distributions come with Tcl/Tk pre-installed, but if you don’t have them installed you can use your distribution’s package manager to install them.
    • A development environment: In order to install Tkinter, you will need to have a development environment set up on your system. This typically includes a compiler (such as GCC) and the make utility. If you don’t have these tools installed, you can use your distribution package manager to install them.

    Install Tkinter in Linux

    Python Tkinter library packages are available under the default package repositories. You can install it using the system’s package manager to install the Python Tkinter module based on the operating system.

    • On Debian-based Linux (Ubuntu, Debian, Pop!_OS):
      sudo apt-get install python3-tk 
      
    • On Arch-based Linux systems:
      sudo pacman -S tk 
      
    • On CentOS, RedHat, and Oracle Linux systems:
      sudo yum install -y tkinter tk-devel
      
    • On Fedora-based Linux systems:
      sudo dnf install python3-tkinter 
      

    This will install the Tkinter module on your system.

    Verify the Tkinter installation

    Once the Python Tkinter module is successfully installed on your system. The following command will show you the Tkinter versions.

    python3 -m tkinter 
    

    The below screenshot shows that Python Tkinter 8.6 is installed.

    How to Install Python Tkinter on Linux
    Verify Python Tkinter Module

    Running an Example with Tkinter

    Let’s make a sample Python program using the Tkinter module. Create a file `example.py` file with the following content.

    1
    2
    3
    4
    5
    6
    7
    from tkinter import *
    window=Tk()
    lbl=Label(window, text="Welcome to Tecadmin.net", font=("Helvetica", 16))
    lbl.place(x=60, y=50)
    window.title('Hello Python')
    window.geometry("400x150+10+10")
    window.mainloop()

    Now, run the Python script with the following command.

    python3 example.py 
    

    You should see the following result.

    How to Install Python Tkinter on Linux
    Running a sample Python program

    Conclusion

    In this tutorial, we learned how to install Tkinter on a Linux system using either pip or apt-get. We also learned how to import and use Tkinter in our Python scripts. Tkinter is a powerful library that allows us to create attractive and functional GUI applications in Python, and it is widely used in the Linux ecosystem. With this knowledge, you should be able to use Tkinter to create your own GUI applications on a Linux system.

    Python Modules Tkinter
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    sleep Command in Linux with Examples

    20 Basic Linux Commands for the Beginners (Recommended)

    tail Command in Linux with Examples

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Test Your Internet Speed from the Linux Terminal
    • 11 Practical Example of cat Command in Linux
    • sleep Command in Linux with Examples
    • 20 Basic Linux Commands for the Beginners (Recommended)
    • tail Command in Linux with Examples
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.