简体   繁体   English

在 PyCharm/Windows 上安装 tkinter

[英]Installing tkinter on PyCharm/Windows

So I have been trying lots of things and googled for this (many answers to this question on stackoverflow, but none worked for me).所以我一直在尝试很多事情并为此进行了谷歌搜索(stackoverflow 上这个问题的许多答案,但没有一个对我有用)。 Basically I have PyCharm on Windows. I have a python project using python 3.8 (virtualenv).基本上我在 Windows 上有 PyCharm。我有一个使用 python 3.8 (virtualenv) 的 python 项目。 I'm trying to use 'tkinter' in this project but this import fails:我正在尝试在此项目中使用“tkinter”,但此导入失败:

import tkinter

在此处输入图像描述

So I try the suggestion of installing future package. That seems to work (no errors).所以我尝试安装 future package 的建议。这似乎有效(没有错误)。 I restart PyCharm but after that the error simply remains.我重新启动 PyCharm 但之后错误仍然存在。 I also tried to manually install 'tkinter' package. So I look in 'Available Packages' and search for 'tkinter'.我还尝试手动安装“tkinter”package。所以我查看“可用包”并搜索“tkinter”。 I see lots of packages starting with 'tkinter' (like 'tkinter-nav', 'tkinter-math', ...) but no 'tkinter'.我看到很多以“tkinter”开头的包(比如“tkinter-nav”、“tkinter-math”……)但没有“tkinter”。 Installing any of these other tkinter packages doesn't help.安装这些其他 tkinter 软件包中的任何一个都没有帮助。

So I'm a bit stuck now.所以我现在有点卡住了。 I'm using Windows 10 btw.我正在使用 Windows 10 顺便说一句。

Thanks for the help谢谢您的帮助

Try using import tkinter as tk or from tkinter import * normally more compatible & workable with more addons;尝试使用import tkinter as tkfrom tkinter import *通常更兼容和适用于更多插件; or at least to my experience或者至少根据我的经验

"import tkinter" can be employed as long as you the word tkinter is used when creating your objects, such as:只要您在创建对象时使用单词 tkinter 就可以使用“import tkinter”,例如:

var = tkinter.StringVar()
username_box = tkinter.Entry(root, textvariable=var, font=("Arial", 14))
username_box.pack(padx=10, pady=10)

see https://docs.python.org/3/library/tkinter.htmlhttps://docs.python.org/3/library/tkinter.html

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

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