运行应在Raspberry Pi3上生成GUI的进程会导致tkinter.TclError

时间:2018-08-28 14:08:01

标签: python tkinter raspberry-pi fabric

我有多个Raspberry Pi 3的无线网络。要在我使用的光纤网络上的所有设备上并行并远程运行进程。所有的Pi都配备了Elecrow 5“ HDMI触摸显示器。我现在想在项目中添加一个GUI以显示ip地址以及Pi当前在程序的哪个阶段。作为第一种方法,我只想显示信息没有通过按钮左右的交互。

如果我在Pi的本地运行我的GUI文件,它就可以正常工作。我想在Mac上的所有Pi上并行运行它时,从所有设备上都会收到相同的错误:

out: Traceback (most recent call last):
out:   File "gui.py", line 108, in <module>
out:     main()
out:   File "gui.py", line 95, in main
out:     root = tk.Tk()
out:   File "/usr/lib/python2.7/lib-tk/Tkinter.py",line 1823, in __init__
out:     self.tk = _tkinter.create(screenName,  baseName, className, interactive, wantobjects, useTk, sync, use)
out: _tkinter.TclError: no display name and no $DISPLAY environment variable

我已经在fabfile中为GUI定义了以下任务:

@parallel
def start_gui():
    code_dir = '/home/pi/test-python'

    with cd(code_dir):
        run("python gui.py")

我花了一些时间来研究这个问题,但似乎没有一种解决方案适合我的情况。有谁知道我该如何设置此显示环境变量,以便可以通过结构运行程序?

谢谢

编辑:我找到了一个非常简单的解决方案,只花了2个小时就阅读了结构文档,但这是值得的。对于只想对此快速解决方案的任何人,我都会发布fabfile的代码:

@parallel
def start_gui():
  code_dir = '/home/pi/test-python'

  with cd(code_dir):
      with settings(password='1234'):
          with shell_env(DISPLAY=':0'):
              run("python gui.py")

0 个答案:

没有答案