Skip to content

wxPython: Sample Program

Randalphwa edited this page Apr 30, 2025 · 1 revision

Creating a main window and running it is easy to do. Using wxUiEditor, create a wxFrame window (in this example, the class name is created as MainFrame). Generate the file and open it in an editor. At the end of the file, you will see the following comment block:

# ************* End of generated code ***********
# DO NOT EDIT THIS COMMENT BLOCK!
#
# Code below this comment block will be preserved
# if the code for this class is re-generated.
# ***********************************************

After this comment block, enter the following code and then save the file.

class App(wx.App):
    """Application class."""
    def OnInit(self):
        """Initialize the application."""
        frame = MainFrame(None, title="My Python Application", pos = wx.Point(512, -1))
        self.SetTopWindow(frame)

        frame.Show(True)
        return True

app = App()
app.MainLoop()

Now all you need to do is enter the following in a command line where my_file.py is the name of the file you created:

python my_file.py

Clone this wiki locally