Create a Python-GUI app in Docker (PySimpleGUI)

What you can learn in this article

--Building a PySimple GUI development environment using Docker [PySimple GUI] --Building a GUI development environment using Docker [Docker & X11 & VcXsrv]

Prerequisites

--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)

Host-side configuration and container preparation

Host side settings (introduction of VcXsrv)

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!

Container preparation

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

Using PySImple GUI

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.

Postscript

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

Create a Python-GUI app in Docker (PySimpleGUI)
Create a simple GUI app in Python
Until you create a new app in Django
[Docker] Create a jupyterLab (python) environment in 3 minutes!
Create a function in Python
Create a dictionary in Python
Create a Todo app with Django ① Build an environment with Docker
Create a CSV reader in Flask
Create a DI Container in Python
Create a binary file in Python
Create a Kubernetes Operator in Python
Create a random string in Python
Create a LINE Bot in Django
I want to create a pipfile and reflect it in docker
Create a JSON object mapper in Python
Create a simple web app with flask
Launch a Flask app in Python Anywhere
[GPS] Create a kml file in Python
Create a web service with Docker + Flask
Introduction to docker Create ubuntu environment in ubuntu
Create a matrix with PythonGUI (text box)
Use WebDAV in a Portable Docker environment
Create a web service in Flask-SQLAlchemy + PostgreSQL
Create a beauty pageant support app using PyLearn2
I want to create a window in Python
Create a standard normal distribution graph in Python
How to create a JSON file in Python
Create a matrix with PythonGUI (tkinter combo box)
Create a protein sequence mutation library in pandas
Create a custom search command in Splunk (Streaming Command)
Create a simple momentum investment model in Python
Create a new page in confluence with Python
Create a datetime object from a string in Python (Python 3.3)
How to create a multi-platform app with kivy
Create a package containing global commands in Python
Create a Mac app using py2app and Python3! !!
How to create a Rest Api in Django
Create a MIDI file in Python using pretty_midi
Create a loop antenna pattern in Python in KiCad
Create a web server in Go language (net/http) (2)
Create a data collection bot in Python using Selenium
Create a Todo app with Django REST Framework + Angular
Create a native GUI app with Py2app and Tkinter
[LINE Messaging API] Create a rich menu in Python
Create a Todo app with the Django REST framework
Create a plugin to run Python Doctest in Vim (1)
Create a Todo app with Django ③ Create a task list page
In Python, create a decorator that dynamically accepts arguments Create a decorator
Create an app that guesses students with python-GUI version
Create a Layer for AWS Lambda Python with Docker
Create a web server in Go language (net / http) (1)
To myself as a Django beginner (1) --Create a project app--
[kotlin] Create a real-time image recognition app on android
To myself as a Django beginner (4) --Create a memo app--
Create a fake Minecraft server in Python with Quarry
Create a Todo app with Django ⑤ Create a task editing function
[Linux] Create a self-signed certificate with Docker and apache
Create a Django schedule
Create a Python module
dict in dict Makes a dict a dict
Create a Bootable LV