here is the source code:
import wxThe first new is we define our new Frame class which named MyFrame,it's subclass the wx.Frame.for the simple reason we do nothing in this class,so we put a pass key word in it.
class MyFrame(wx.Frame):
pass
class MyApp(wx.App):
def OnInit(self):
self.frame=MyFrame(parent=None,title="Top window")
self.frame.Show()
self.SetTopWindow(self.frame)
return True
if __name__ == '__main__':
app=MyApp()
app.MainLoop()
Then in our MyApp class we use our defined MyFrame class,because of maybe there were many window to display in a same application ,so we should tell application we want to show this frame on the top of all other the SetTopWindow() is a method of wx.App,it told programe the self.frame will be displayed on the top.
the final important thing I want to introduce is
if __name__ == '__main__':I called it with "application entry",it used to test wether the module is being run as program or was imported by another moudle,if the moudle was imported it's __name__ attribute will be same as its file name,but if the module is being executed,rather than imported,Python overrides the __name__ with '__main__'.Then it's giving us a chance to have the module behave differently when executed directly,it's cool,isn't it?

No comments:
Post a Comment