简体   繁体   English

不能在 Ubuntu 上的 pycharm 上使用 tkinter

[英]Can't use tkinter on pycharm on Ubuntu

I would like to use tkinter to develop a simple GUI for a project.我想使用 tkinter 为项目开发一个简单的 GUI。 After reading a few questions, I installed it through the command看了几个问题,我通过命令安装了

sudo apt-get install python-tk , which I ran from the Pycharm terminal sudo apt-get install python-tk ,我从 Pycharm 终端运行

However, when I type import tkinter from the Python console I get the following error (I tried typing both tkinter and Tkinter): ModuleNotFoundError: No module named 'tkinter'但是,当我从 Python 控制台键入import tkinter时,我收到以下错误(我尝试同时键入 tkinter 和 Tkinter): ModuleNotFoundError: No module named 'tkinter'

Which is odd because Pycharm seems to be able to see the package, hence it suggests me the name as you can see in this image这很奇怪,因为 Pycharm 似乎能够看到 package,因此它建议了我在这张图片中看到的名称

在此处输入图像描述

I tried running python from the Ubuntu terminal and I was able to import tkinter without error, so I deduce tkinter is installed but I can't use it from Pycharm. I tried running python from the Ubuntu terminal and I was able to import tkinter without error, so I deduce tkinter is installed but I can't use it from Pycharm. I don't know how I can solve this, do you have any suggestion?我不知道我该如何解决这个问题,你有什么建议吗?

I managed to solve this by creating a new project and setting as interpreter the one that was able to see tkinter, in my case it is python3 .我设法通过创建一个新项目并将能够看到 tkinter 的解释器设置为解释器来解决这个问题,在我的例子中是python3 I tried switching interpreters from the button on the lower right but it didn't actually work properly and got stuck on the same interpreter, that's why I created a new project我尝试从右下角的按钮切换解释器,但它实际上并没有正常工作并且卡在同一个解释器上,这就是我创建一个新项目的原因

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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