From the course: Rapid Application Development with Python

Introducing wxPython - Python Tutorial

From the course: Rapid Application Development with Python

Start my 1-month free trial

Introducing wxPython

- We've already installed wxPython, so let's build a Hello World At with it. I'll use Visual Studio Code to do this. I'm starting with a new file and I'll save it as wxHelloWorld.py. Now that Visual Studio Code knows that we have a Python script, we get the Python editing highlights. Let's write our first wxPython program. The first thing I need to do is import WX, to import the wxLibrary to provide access to the full wxPython capability. Then I'll create the wxPython GUI application by saying app equals wx.App false. And then create the frame for adding GUI components using frame equals wxFrame None because there's no parent wx.ID Any, to request that Python assign a unique variable of its own choice to this object and using a Window title of Hello World. We'll then activate this Window using the show method, frame.Show, True. We complete the GUI program by putting it into a loop and waiting for an event app.Mainloop. And as we haven't written any events ourselves, the only event in this program is to close the app. Let's save this and run it using the run button at the top right. We get a Window with the title of Hello World. Okay, we've created and run our first wxPython GUI program.

Contents