当前位置:  开发笔记 > 编程语言 > 正文

PythonAnywhere:尝试使用easygui模块时出现Tkinter.py错误

如何解决《PythonAnywhere:尝试使用easygui模块时出现Tkinter.py错误》经验,为你挑选了1个好方法。

我的儿子正在尝试使用pythonAnywhere执行一个小程序.

import random, easygui
secret = random.randint(1,99)
guess = 0
tries = 0
easygui.msgbox ("AHOY! I'm the Dread Pirate Roberts, and I have a    secret!\n"
"It is a number from 1 to 99. I'll give ye 6 tries.")
while guess != secret and tries < 6:
    guess = easygui.integerbox ("What's yer guess, matey?")
    if not guess: break
    if guess < secret:
        easygui.msgbox (str(guess) + "is too low, ye scurvy dog!")
    elif guess > secret:
        easygui.msgbox (str(guess) + "is too high, landlubber!" )
    tries = tries + 1
if guess == secret:
    easygui.msgbox ("Avast! Ye got it! Found me secret, ye did!" )
else:
    easygui.msgbox ("No more guesses! The number was" + str(secret))

从bash控制台运行代码时,会抛出以下错误:

File "NumGuess.py", line 6, in 
    It is a number from 1 to 99. I'll give ye 6 tries.""")
  File "/home/016646/.local/lib/python2.7/site-    packages/easygui/boxes/derived_boxes.py", line 216, in msgbox
    cancel_choice=ok_button)
  File "/home/016646/.local/lib/python2.7/site-packages/easygui/boxes/base_boxes.py", line 66, in buttonbox
    boxRoot = Tk()
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1767, in __init__
    self.tk = _tkinter.create(screenName, baseName, className,     interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable

easygui模块是使用pip install --user easygui安装的,正如PythonAnywhere论坛上所建议的那样.

由于PA是一个基于网络的环境,我不确定是否有一些额外的细微差别.ssh进入系统时,网上有一些关于此错误的建议.但是,PA是通过Web登录访问的,因此可能不适用.



1> Bryan Oakley..:

Tkinter(因此,easygui)需要一个实际的屏幕来绘制.错误告诉你它无法找到屏幕.Tkinter根本不适合在基于Web的环境中运行.

有关tkinter和其他gui库的pythonanywhere帮助页面的更多信息.

推荐阅读
拾味湖
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有