16

I used sudo apt-get install python3.6-tk and it works fine. Tkinter works if I open python in terminal, but I cannot get it installed on my Pycharm project. pip install command says it cannot find Tkinter. I cannot find python-tk in the list of possible installs either.

Is there a way to get Tkinter just standard into every virtualenv when I make a new project in Pycharm?

Edit: on Linux Mint

Edit2: It is a clear problem of Pycharm not getting tkinter guys. If I run my local python file from terminal it works fine. Just that for some reason Pycharm cannot find anything tkinter related.

TheProgramMAN123
  • 487
  • 1
  • 5
  • 13

7 Answers7

7

For python 2 use:

sudo apt-get install python-tk

For python 3 use:

sudo apt-get install python3-tk

When you display info about packages it states:

Tkinter - Writing Tk applications with Python2 (or Python 3.x)


But my assumption is that PyCharm created it's own virtualenv for you project, so you are probably using wrong python interpreter in PyCharm.

Open your PyCharm project. Go to File->Settings->Project->Project Interpreter. At top, you will see what python interpreter is PyCharm using for a current project. If that's not the system one you have, find path to system interpreter and add it to Python Interpreters in PyCharm.

More details on PyCharm Documentation.

Dinko Pehar
  • 5,454
  • 4
  • 23
  • 57
  • Hi @TheProgramMAN123 if this or any answer has solved your question please consider [accepting it](https://meta.stackexchange.com/q/5234/179419) by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. – Dinko Pehar Oct 14 '19 at 06:13
7

Make sure you use the right import statement for your version of Python.

Python 2.7

from Tkinter import *

For Python 3.x

from tkinter import *
Mattatat-tat
  • 459
  • 1
  • 7
  • 9
0

Pycharm is having problems with tkinter probably because you're using the flatpak version. I had the same problem with Pycharm as well as VSCode. It wouldn't recognize module tkinter. I tried using the snap version of Pycharm and now it is working perfectly fine. I think you should give it a try before looking for tkinter.

sudo snap install pycharm-community --classic
-1

Python already has tkinter installed. It is a base module, like random or time, therefore you don't need to install it.

Sam
  • 88
  • 7
-1

Pycharm comes with tkinter by default. But there are some circumstances that your installation might be missing tkinter. In that case you have to follow below mentioned steps.

For python 2 use:

sudo apt-get install python-tk

For python 3 use:

sudo apt-get install python3-tk

When you display info about packages it states:

Basically you have to import it

from tkinter import *

top = Tk()
# Code to add widgets will go here...
top.mainloop()
Tharindu Kumara
  • 4,398
  • 2
  • 28
  • 46
-1

To install tkinter in Pycharm, install the module “future” and restart pycharm. Tkinter will be imported, to access it use:

from future.moves import tkinter

If it don't work for you, search where tkinter lies in "future" package using cmd:

$ find . -name "*tkinter*"

and import accordingly.

  • you can check my solution from here https://stackoverflow.com/questions/53797598/how-to-install-tkinter-with-pycharm/68347377#68347377 – Vishwa Pratap Jul 12 '21 at 12:29
-2

For Python 3.8:

sudo apt-get install python3.8-tk
mbomb007
  • 3,788
  • 3
  • 39
  • 68