小编Amo*_*Iju的帖子

如何在 wsl 上修复 python3.8 中的 tkinter?

我试图学习基于 GUI 的 python,因此我使用了 Tkinter 库。我的操作系统是 Windows,但我已安装 Ubuntu wsl 作为我的默认终端,并使用 wsl vscode 作为我的默认文本编辑器。我只是使用此示例代码创建一个基本窗口来检查它是否有效:

from Tkinter import *
def onclick():
pass
root = Tk()
text = Text(root)
text.insert(INSERT, "Hello.....")
text.insert(END, "Bye Bye.....")
text.pack()
text.tag_add("here", "1.0", "1.4")
text.tag_add("start", "1.8", "1.13")
text.tag_config("here", background="yellow", foreground="blue")
text.tag_config("start", background="black", foreground="green")
root.mainloop()
Run Code Online (Sandbox Code Playgroud)

结果发现它不适用于 python3.8。 终端错误消息 我查找了多个资源和论坛,但找不到任何合适的解决方案。以下是我提到的几个链接: https://realpython.com/python-gui-tkinter/ https://tkdocs.com/tutorial/install.html https://askubuntu.com/questions/1224230/how -安装-tkinter-for-python-3-8。我发现的一个解决方法是安装使用 python3.7 的 anaconda 并使用 Windows 终端(使用 pycharm 而不是 vscode)。看起来它运行正常。 使用 python3.7 的 GUI

问题是.. 与 Windows 命令行相比,我更喜欢 wsl 和 vscode,并且我想恢复到它。有什么解决办法吗?我真的不想在这条路径上浪费太多时间,因为我之前有过一次糟糕的经历(但如果它能解决我的问题,我愿意再做一次)。谢谢你听我说完。

python ubuntu tkinter windows-subsystem-for-linux

1
推荐指数
2
解决办法
1万
查看次数