0

I want to run python script that only generates image from tkinter canvas. The error I am having is

_tkinter.TclError: couldn't connect to display ":0"

I have find some simmilar problems here so my attempt is:

running test.py

import tkinter
import random

canvas = tkinter.Canvas()  # <-- error occurs here
canvas.pack()

x = random.randrange(380)
y = random.randrange(260)
canvas.create_text(x, y, text='PYTHON')
canvas.postscript(file="my_drawing.ps", colormode='color')

inside docker

docker run --rm 
-e DISPLAY=$DISPLAY 
-v /tmp/.X11-unix:/tmp/.X11-unix 
-v $PWD:/app 
python:3.5.2-alpine python /app/test.py

However I have xvfb on my machine and it's also inside container after docker add so I don't really understand how to run tkinter without touching env $DISPLAY

Does anybody experienced similar problem?

Thanks

Martin Reguly
  • 133
  • 1
  • 9
  • docker doesnt do great with GUI stuff .... best case senario you solve your issue with black magic and hackery and have a super fragile container that only you can help trouble shoot ... at least thats my experience with it – Joran Beasley Feb 06 '19 at 21:56
  • This container will just execute code and save IMG from tkinter canvas. There isn't greater purpose for the container just to be fast. That's why I don't want install additional software inside container. Have you experienced with such a magic that can help me? – Martin Reguly Feb 07 '19 at 15:26

1 Answers1

0

You need a display server for tkinter so i dont think there is any other way than installing a x server on the container itself (i am not sure if it is possible)

dvtkrlbs
  • 53
  • 1
  • 4
  • As you see in docker script I am adding part of X server that handles display but still no luck. – Martin Reguly Feb 07 '19 at 15:28
  • The x server needs a display device you can give docker access to all divices with docker run ..... —unpriviledged but i wouldnt use it – dvtkrlbs Feb 07 '19 at 17:02