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()
作者: pzxbc
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

浙公网安备 33010602011771号