简体   繁体   中英

how to install tkinter with Pycharm?

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.

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 .

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 *

Ok so the question was about Pycharm and Tkinter, I just don't think it can be done. Maybe by changing some obscure settings that I have not found yet. I solved it by just using vscode and the built in terminal to quickly test a piece of code. A virtual environment created outside Pycharm for some reason does not work (well) inside Pycharm.

A bit less functionality, but at least you don't get fake errors all over the place. And don't have to deal with trying for hours to change some obscure setting to make it work.

Had similar problems using Pycharm and Flask.

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

I have the very same issue with Pycharm (PyCharm 2022.3.1 Community Edition). I've tried find. -name "*tkinter*" find. -name "*tkinter*" It returns ./venv/lib/python3.10/site-packages/future/moves/tkinter I installed the module "future" then used "from future.moves import tkinter" still not working, I don't know how to proceed.

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

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()

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.

For Python 3.8:

sudo apt-get install python3.8-tk

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM