Python установка tkinter linux

How to install Tkinter? [duplicate]

How the hell to install tkinter on to my PC ?
I tried for week to install it. I can not figure it out. Please, Help.
How does it work ? Is there a site you install it from or what ?

In some Linux distributions Tkinter comes in a separate package, and have to explicitly installed. Given the wording of the question, I guess the O.P. is on Windows though, where it is already installed. Otherwise, just search for «tkinter» in your linux package manager — the exact name may vary (e.g. «python-tkinter», or just «tkinter» in others)

4 Answers 4

Should be there already man.

I assume you’re using Windows. If so.

Step 1. Ignore the people who say to import tkinter as tk or «It should already be there».

You’re not the only person to have this problem despite apparently every post on the Internet telling you one of those two (utterly unproductive) statements. *deep breath*

Step 2. Understand what you’re trying to do.

You’re trying to do two things. The first is to install the Tk GUI toolkit, also known as Tcl/Tk . This is a collection of software that exists independently of Python which allows for GUI development. The second is to have Python interact with Tcl/Tk . This is done with the tkinter module which allows you to call Tcl/Tk using Python.

The Python installer, by default, installs Tcl/Tk along with tkinter . The tkinter module is part of the standard library. Because tkinter is not useful without Tcl/Tk also installed, someone, somewhere, at some time, decided it wasn’t worth packaging tkinter separately. I don’t know why.

Maybe you didn’t install Tcl/Tk and tkinter when Python installed. Maybe you decided to use a different GUI framework. Maybe you thought «Why should I install something that I’ll never use, along with an IDE I’ll never use.» Maybe you later found out that a third-party library like seaborn requires it. *deep breath*

Step 3. Figure out how you want to accomplish the two things you’re trying to do.

Читайте также:  Linux get https file

Option 1. Install Tcl/Tk manually. Then maybe you can find some saint who has packaged tkinter for you. But maybe the versioning isn’t correct. So you could compile it from source and/or learn a lot about how Python packaging works.

Option 2. Rerun the Python installer. Select «Modify». Make sure that the » tcl/tk and IDLE » checkbox is ticked and press «Next» a bunch.

If all else fails, burn everything down and start from scratch. But hopefully the second option works for you like it did for me. 🙂

Источник

Install Tkinter on Ubuntu Linux
Install Tkinter on Ubuntu and other Debian-based Linux distributions

Before you start the Tkinter tutorial you will need to have a working installation of PyQt5 on your system. If you don’t have either set up yet, the following steps will guide you through how to do this on Linux.

This guide is also available for macOS. On Windows, Tkinter is installed by default with Python.

Install Tkinter via apt

Packages for Tkinter are available in the repositories of most distributions. In Ubuntu you can install either from the command line or via «Software Center». The package you are looking for is named python3-tk .

You can also install these from the command line as follows —

sudo apt install python3-tk 

After install is finished, you should be able to run python3 (or python ) and import tkinter without errors.

Python 3.7.6 Type "help", "copyright", "credits" or "license" for more information. >>> import tkinter >>> 

Create GUI Applications with Python & Qt6

Downloadable ebook (PDF, ePub) & Complete Source code

[[ discount.discount_pc ]]% OFF for the next [[ discount.duration ]] [[discount.description ]] with the code [[ discount.coupon_code ]]

Purchasing Power Parity

Developers in [[ country ]] get [[ discount.discount_pc ]]% OFF on all books & courses with code [[ discount.coupon_code ]]

Never miss an update

Enjoyed this? Subscribe to get new updates straight in your Inbox.

Install Tkinter on Ubuntu Linux was written by Martin Fitzpatrick .

Martin Fitzpatrick has been developing Python/Qt apps for 8 years. Building desktop applications to make data-analysis tools more user-friendly, Python was the obvious choice. Starting with Tk, later moving to wxWidgets and finally adopting PyQt.

Читайте также:  Linux приставка для телевизора

Install Tkinter on Ubuntu Linux was published in installation on May 21, 2019 (updated March 16, 2023 )

  • Topics
  • Where do I begin?
  • Data Science
  • Packaging & Distribution
  • Databases & SQL
  • QML/QtQuick
  • Learn the fundamentals
  • Raspberry Pi
  • Games
  • Start

Follow us for new tutorials

Источник

How to install tkinter for python 3.8?

I have Python 3.8 on Ubuntu 16.04. I installed python3-tk (it is required for showing plots in matplotlib):

Reading package lists. Done Building dependency tree Reading state information. Done python3-tk is already the newest version (3.5.1-1). 0 upgraded, 0 newly installed, 0 to remove and 12 not upgraded. 
Reading package lists. Done Building dependency tree Reading state information. Done python3.8-tk is already the newest version (3.8.2-1+xenial1). 0 upgraded, 0 newly installed, 0 to remove and 12 not upgraded. 
$ python3.8 -m tkinter Traceback (most recent call last): File "/usr/local/lib/python3.8/runpy.py", line 184, in _run_module_as_main mod_name, mod_spec, code = _get_module_details(mod_name, _Error) File "/usr/local/lib/python3.8/runpy.py", line 143, in _get_module_details return _get_module_details(pkg_main_name, error) File "/usr/local/lib/python3.8/runpy.py", line 110, in _get_module_details __import__(pkg_name) File "/usr/local/lib/python3.8/tkinter/__init__.py", line 36, in import _tkinter # If this fails your Python may not be configured for Tk ModuleNotFoundError: No module named '_tkinter' 

5 Answers 5

If you installed python3.8 using apt (via ppa:deadsnakes/ppa), it can be installed using apt too, the name of library is python3.8-tk .

sudo apt install python3.8-tk 

In my case, it solves the problem. For instance, now I can use matplotlib in python3.8 which requires tkinter.

Recompile and reinstall python3.8 specifying path to folders with tcl, tk includes and libraries.

sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev python-tk python3-tk tk-dev cd ~/Downloads wget https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tgz tar -xvf Python-3.8.2.tgz cd Python-3.8.2 

Edit ./configure file the next way: replace . for next lines:

 --with-tcltk-includes='-I/usr/include' --with-tcltk-libs='-L/usr/lib' ./configure make -j2 # replace 2 by number of processor cores you have sudo make install $ python3.8 Python 3.8.2 (default, May 11 2020, 14:30:03) [GCC 5.4.0 20160609] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import tkinter >>> 

Python 3.8 installed through apt and pyenv on 16.04 does not include tkinter, as I think or there’s a some bug that does not allow to import it. Only rebuilding helped. Previously I’ve used 20.04 with built in Python 3.8 version, which supports tkinter with only additional packages installing as it is for Python 3.5 on 16.04.

python3.8-tk installation as Ankur A Sharma said is also required. I’ve forget to mention it. But it is not sufficient for 16.04, at least in my case.

Читайте также:  Смена пароля через командную строку linux

Additional requirement from OP’s comment:

sudo ./configure --with-tcltk-includes='-I/usr/include -I/usr/include/tcl' --with-tcltk-libs='-L/usr/lib -ltcl -ltk' --enable-optimizations 

Источник

How to Install Python Tkinter on Linux

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.

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 
sudo yum install -y tkinter tk-devel 
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.

The below screenshot shows that Python Tkinter 8.6 is installed.

How to Install Python Tkinter on Linux

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.

Источник

Оцените статью
Adblock
detector