简体   繁体   English

Tkinter 不是 Ubuntu 20.04 中的模块

[英]Tkinter is not a module in Ubuntu 20.04

I was on my computer and I was trying to code some tkinter code but when I put the starters in Pycharm, there was an error saying that Tkinter is not a module and then I tested it as tkinter and it was also not found.我在我的电脑上,我试图编写一些 tkinter 代码,但是当我将启动器放入 Pycharm 时,出现一个错误,指出 Tkinter 不是一个模块,然后我将它测试为 tkinter,但也没有找到。 Can someone please help me get this sorted out as I really want to do some coding and this is slowing it down.有人可以帮我解决这个问题,因为我真的想做一些编码,这会减慢它的速度。

Thanks!谢谢!

Is it installed on your OS?它安装在您的操作系统上吗? You can try sudo apt install python3-tk or sudo apt install python-tk .您可以尝试sudo apt install python3-tksudo apt install python-tk

You could also try installing it via pip: pip install python-tk您也可以尝试通过 pip 安装它: pip install python-tk

For Python 3, beyond installing with对于 Python 3,除了安装

sudo apt-get install python3-tk

the following will help to get it to work:以下内容将有助于使其正常工作:

instead of from Tkinter import * use from tkinter import *而不是from Tkinter import *使用from tkinter import *

or generic suitable for both Python2 and Python 3或通用适用于 Python2 和 Python 3

import sys

if sys.version_info[0] == 3:
    from tkinter import *
else:
    from Tkinter import *

Similarly: instead of import Tkinter as tk use import tkinter as tk类似地:代替import Tkinter as tk使用import tkinter as tk

or generic suitable for both Python2 and Python 3或通用适用于 Python2 和 Python 3

import sys
if sys.version_info[0] == 3:
    import tkinter as tk
else:
    import Tkinter as tk

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

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