'How to run tkinter inside a docker container on MacBook Pro?
I'm trying to run a python GUI application that uses tkinter module inside a docker container on my MacBook Pro.
So I installed XQuartz and followed this tutorial to run a simple tkinter program inside a docker container.
And here's the error message I got
Traceback (most recent call last):
File "/app/tkinter_app.py", line 4, in <module>
root_window = tk.Tk()
File "/usr/local/lib/python3.8/tkinter/__init__.py", line 2270, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: couldn't connect to display "/private/tmp/com.apple.launchd.knFz0UzqxP/org.xquartz:0"
The value of my DISPLAY environment variable is /private/tmp/com.apple.launchd.knFz0UzqxP/org.xquartz:0.
Anyone knows how to solve this error?
Here's the Dockerfile in the tutorial
# Slim version of Python
FROM python:3.8.12-slim
# Download Package Information
RUN apt-get update -y
# Install Tkinter
RUN apt-get install tk -y
# Commands to run Tkinter application
CMD ["/app/tkinter_app.py"]
ENTRYPOINT ["python3"]
Line 4 of /app/tkinter_app.py is root_window = tk.Tk().
My MacOS version is 11.6.1.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
