Quantcast
Channel: Planet Python
Viewing all articles
Browse latest Browse all 22873

IslandT: wxPython Tutorial — Create the wxPython child class object

$
0
0

Before I start, if you guys happen to know the creator of wxPython please do ask him this question: Why are you using the term wxPython instead of WxPython? I just feel curious about that!

Alright, after a few articles about Tkinter it is time to write the first wxPython tutorial and in this simple tutorial I am going to create a child class object from wxPython class where this object will be used later in all the tutorial articles about wxPython.

If you have forgotten how I create the class object please refer to this child class post to refresh you memory a little bit!

And here is how to create the child class of wxPython.

import wx

class DerivedApp(wx.App):

    def OnInit(self):
        the_frame = wx.Frame(None, -1) # create the top-level window
        the_frame.Show(True)
        return True

According to the wxPython website:-

OnInit will usually create a top window as a bare minimum. Unlike in earlier versions of wxPython, OnInit does not return a frame. Instead, it returns a boolean value that indicates whether processing should continue (True) or not (False).

I personally think that OnInit will get called after the user has created the child class object as shown in the below two lines of code!

wxapp = DerivedApp() # create the child class object
wxapp.MainLoop() # this loop will continue running until you close the top-level window

After the program has entered the main loop the top-level window will appear on the screen!

Phew, although it is simple, trust me, this is the method I use to learn Python programming language one bit at a time!


Viewing all articles
Browse latest Browse all 22873

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>