I'm trying to use the Python GUI wx
(installable via pip install wxPython
) in the following minimal app:
import wx
app = wx.App()
Running this snippet returns the following:
This program needs access to the screen. Please run with a Framework
build of python, and only when you are logged in on the main display
of your Mac.
Does anyone know how to help wx gain "access to the screen", or what a "Framework build of Python" is? I'd be grateful for any help others can offer with these questions!
To sum things up, we learned that wxPython is popularly used for developing GUI-based desktop applications in Python, and that Python also has some other cool alternatives for it. We went through the commands to download and install it on all popular Operating Systems.
WxPython is quite easy to install on Mac and Windows using pip package manager. If you have pip installed in your system, run the following command to download to install wxPython:
In order to use anaconda's python executable and wxPython on a mac you will need to run "pythonw" (instead of "python"). This calls the python executable that is compatible with wxPython.
When you run this version of the code, your application should look like the following: If you’d like to learn more about sizers, the wxPython documentation has a nice page on the topic. While your application looks more interesting visually, it still doesn’t really do anything. For example, if you press the button, nothing really happens.
wxPython on Mac within a virtual environment throws this error, as explained by wxPython website here: https://wiki.wxpython.org/wxPythonVirtualenvOnMac
If you are not running it in a virtual environment and still receive this error, try running your script that uses wxpython with "pythonw" instead of "python". Ex:
pythonw hello.py
^See section "4.1.2 Running Scripts with a GUI" (on MacOS) from the following page in the Python Docs to see this python quirk explained: https://docs.python.org/3/using/mac.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With