Docker中的Python Tkinter .TclError:无法连接显示 [英] Python Tkinter in Docker .TclError: couldn't connect to display
问题描述
我是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屋!