wxPython获取应用程序对象app和主窗口对象MainFrame

  wxPython中获取应用程序对象App以及主窗口对象MainFrame:

# -*- coding: utf-8 -*-

import wx

class MyFrame(wx.Frame):
def __init__(self, parent, id=wx.ID_ANY, title="",
pos=wx.DefaultPosition, size=wx.DefaultSize,
style=wx.DEFAULT_FRAME_STYLE,
name="MyFrame"):
super(MyFrame, self).__init__(parent, id, title,
pos, size, style, name)

# Attributes
self.panel = wx.Panel(self)
button = wx.Button(self.panel, label = "Push Me",
pos = (50, 50))
# Event handlers
self.Bind(wx.EVT_BUTTON, self.OnButton, button)

def OnButton(self, event):
#获取应用程序对象App
print "\nGet the Application Object:"
app = wx.GetApp()
print "%s" % repr(app)
print "\nGet the Frame from the App:"
#获取主窗口对象MainFrame
frame = app.GetTopWindow()
print "%s" % repr(frame)

class MyApp(wx.App):
def OnInit(self):
self.frame = MyFrame(None, title='The Main Frame')
self.SetTopWindow(self.frame)
self.frame.Show()

return True

if __name__ == '__main__':
app = MyApp(False)
app.MainLoop()



posted @ 2011-12-14 21:18  pzxbc  阅读(2008)  评论(0)    收藏  举报