Ubuntu18.04 wxPython 4.0.4 Python 3.7
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?"
I couldn't type "DISPLAY =: 0" in the terminal or set DISPLAY in the env variable in launch.json.
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.
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