Docker 中的 Python Tkinter .TclError:无法连接到显示 [英] Python Tkinter in Docker .TclError: couldn't connect to display

查看:37
本文介绍了Docker 中的 Python Tkinter .TclError:无法连接到显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Python 新手,正在尝试构建一个小应用程序.它需要是一个 GUI 应用程序,我想用 docker 将它容器化.我收到以下错误,找不到解决方案

I am new to python and am trying to build a small app. It needs to be a GUI app and I was wanting to containerise it with docker. I am getting the following error and can not find a solution

No protocol specified
No protocol specified
Traceback (most recent call last):
  File "tkinker.py", line 7, in <module>
    tinker = Tk()
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1818, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: couldn't connect to display ":0.0"

它在本地启动,但不会在 docker 中启动.我的操作系统是 Xubuntu.

It starts locally but wont start in docker. My OS is Xubuntu.

我已经创建了一个示例应用程序(如下),请参阅 run-test.sh https://github.com/jeremysells/test/tree/master/docker-tkinter

I have created a sample app (below), see run-test.sh https://github.com/jeremysells/test/tree/master/docker-tkinter

推荐答案

此处所述,您需要一个 X11 图形层.
但是由于您已经在 '(X)Ubuntu 上,设置 DISPLAY 应该就足够了:

As described here, you would need an X11 graphic layer.
But since you are already on an '(X)Ubuntu, setting the DISPLAY should be enough:

export DISPLAY=127.0.0.1:0.0

docker run -it -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix yourImage

另请检查XAuthority.

这篇关于Docker 中的 Python Tkinter .TclError:无法连接到显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆