--Building a PySimple GUI development environment using Docker [PySimple GUI] --Building a GUI development environment using Docker [Docker & X11 & VcXsrv]
--Docker and Docker-compose must be installed --Basic usage of Python and Docker ――It's even better to have an overview of X11
I use Docker Toolbox, but I should be able to do it with Docker Desktop (unverified)
Install VcXsrv to display the window of the container on the host side. VcXsrv: Download link
Here, in order to avoid a security error, obtain the IP address of the VM etc. where the container is running. Add the obtained IP address to "x0.hosts" in the folder where VcXsrv is installed.
Normal installation destination: C: \ Program Files \ VcXsrv
Once installed, launch XLanuch with the default settings. OK if it is started on the taskbar!
Create a Dockerfile and Docker-compose.yml.
Docekrfile
#Excerpt of only the minimum necessary parts
FROM python:3.8.2
RUN pip install pysimplegui
Just install PySimpleGUI with pip install. Add your own settings for users, folders, other dependencies, etc.
Docker-compose.yml
version: "3.2"
services:
python-gui:
build: .
restart: always
tty: true
volumes:
-Host side folder:Container side folder
environment:
- DISPLAY=Host IP address:0.0
The X11 settings are set by environment variables. The host IP address here is the IP address of DockerNat or the IP address of the VirtualBox network. (Of course, it must be a network connected to the container)
Qiita reference article: GUI with Docker for Windows (how to not transfer X11 with ssh)
Once this is done, start the container and you're ready to go
docker-compose up -d --build
If you execute the created code, a Window should be created on the host side.
If you get the following error, the X11 settings are not working properly, so review the settings again.
ErrorMessage
abridgement: couldn't connect to display "Host IP address:0.0"
Since this is the main article on environment construction, please refer to the following article for how to create the code.
The official documentation may be solid.
I will also post articles that were helpful in Japanese
-Qiita article: If you use Tkinter, try using PySimpleGUI --There are polite and easy-to-understand articles from the outline to simple examples, and explanation article links for Japanese materials at the end of the article. -Qiita article: Basic usage of PySimple GUI --PDF text explaining each element.
I also wrote an article about how to make an application created in a container into an EXE for Windows. How to implement Python EXE for Windows with Docker container
Recommended Posts