DISPLAY error in wxPython (and traitsui) on vscode

environment

Ubuntu18.04 wxPython 4.0.4 Python 3.7

Background

Hello world of traitsui did not work, so I checked with the following Hello World code whether wxPython used as a toolkit works in the first place.

# First things, first. Import the wxPython package.
import os
import wx

# Next, create an application object.
app = wx.App()
print(app.IsDisplayAvailable())

# Then a frame.
frm = wx.Frame(None, title="Hello World")

# Show it.
frm.Show()

# Start the event loop.
app.MainLoop()

Then, the following error "Unable to access the X Display, is $ DISPLAY set properly?" Screenshot from 2020-07-18 14-15-33.png

I couldn't type "DISPLAY =: 0" in the terminal or set DISPLAY in the env variable in launch.json.

solution

After all, I was able to solve it by specifying environment variables in the code as follows.

# First things, first. Import the wxPython package.
import os
import wx

os.environ["DISPLAY"] = ":0"

# Next, create an application object.
app = wx.App()
print(app.IsDisplayAvailable())

# Then a frame.
frm = wx.Frame(None, title="Hello World")

# Show it.
frm.Show()

# Start the event loop.
app.MainLoop()

Below is the window that is displayed. Screenshot from 2020-07-18 14-21-15.png

Consideration

In the first place, in the vscode terminal, xeyes could not be displayed unless it was set to xeyes -display: 0. In addition, in a normal terminal, Hello World display was possible without taking any special measures, so there seems to be a problem with the terminal implementation of vscode.

Recommended Posts

DISPLAY error in wxPython (and traitsui) on vscode
VScode environment construction (on Mac) & graph display in Python (@browser)
How to suppress display error in matplotlib
Error that occurred in OpenCV3 and its solution Precautions when using OpenCV3 on Mac
Image display and video playback on Neovim Terminal
Display error message when login fails in Django
To write to Error Repoting in Python on GAE
Display and analyze only some columns in CASTable
Put Scipy + Matplotlib in Ubuntu on Vagrant and display the graph with X11 Forwarding
Error in random.shuffle
Error in Pyinstaller
Error in TensorBoard
About import error of numpy and scipy in anaconda
Read the csv file and display it in the browser
Note: CGI (during trial and error) in Vagrant environment
Measure indoor and outdoor temperature and humidity and display on dashboard
Install and develop Git, VSCode, Docker on Chrome OS
Execute the command on the web server and display the result