Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.6k views
in Technique[技术] by (71.8m points)

ubuntu - Python Tkinter in Docker .TclError: couldn't connect to display

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"

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

Check also XAuthority.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

63 comments

56.7k users

...