简体   繁体   English

海龟需要Tkinter吗?

[英]Does Turtle need Tkinter?

So I am new to python and I am working through a turtle racer tutorial.所以我是 python 的新手,我正在学习海龟赛车教程。 I have copied the code exactly and the tutorial shows the code working at this point (though not complete).我已经准确地复制了代码,教程显示了此时的代码(虽然不完整)。 Mine does not.我的没有。 I installed tkinter on my first error that mentioned it, but now I get this error.我在提到它的第一个错误中安装了 tkinter,但现在我收到了这个错误。 I have modified the code a few different ways (included the commented out section using tkinter).我已经用几种不同的方式修改了代码(包括使用 tkinter 注释掉的部分)。 What should I do to fix this error and continue on with my tutorial?我应该怎么做才能修复这个错误并继续我的教程? This is the error I am getting and This is the incomplete code for the racer这是我得到的错误这是赛车手的不完整代码

It seems like it is looking for an environment variable that is not set.似乎它正在寻找未设置的环境变量。

Look into how to set environment variables, specifically $DISPLAY研究如何设置环境变量,特别是 $DISPLAY

Yes, it requires tkinter , it needs the Tk window for your output.是的,它需要tkinter ,它需要Tk window 用于您的 output。 You may refer to this post for clarification: here您可以参考这篇文章进行澄清: 这里

Also, this post here provides a good explanation on how turtle operates in two modes: standalone and embedded.此外, 这里的这篇文章很好地解释了turtle如何在两种模式下运行:独立模式和嵌入式模式。

Figured out the issue.想通了这个问题。 I wasn't realizing the call back to the DISPLAY variable because I was too focused on the Tkinter problems and another user pointed out that part of the error.我没有意识到对 DISPLAY 变量的回调,因为我太专注于 Tkinter 问题,而另一位用户指出了错误的一部分。

I was coding on window's subsystem for linux which doesn't have a GUI.我正在为没有 GUI 的 linux 编写窗口子系统。 So I was just running code like I would on my actual linux machine without thinking.所以我只是像在我的实际 linux 机器上一样运行代码,而不加思考。 I ran the code on my linux machine that has a GUI and it worked without any tkinter code added in. It couldn't find the DISPLAY variable because there wasn't one on WSL.我在我的 linux 机器上运行了代码,它有一个 GUI,它在没有添加任何 tkinter 代码的情况下工作。它找不到 DISPLAY 变量,因为 WSL 上没有。

Basically I just did something a bit dumb and realized my mistake.基本上我只是做了一些愚蠢的事情并意识到我的错误。 Thanks for the help, everyone!谢谢大家的帮助!

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

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