Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wxPython: This program needs access to the screen

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!

like image 779
duhaime Avatar asked Jan 30 '18 21:01

duhaime


People also ask

What is wxPython used for?

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.

How to install wxPython on Mac?

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:

How to use Anaconda's Python executable with 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.

What should my wxPython application look like?

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.


1 Answers

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

like image 99
Nick Weimer Avatar answered Oct 02 '22 22:10

Nick Weimer