WxPython 应用程序组成:
每一个WxPython应用程序,都有一个应用程序对象。这个应用程序对象拥有至少一个根窗口,这是WxPython程序的必须部分,另外在应用程序对象中实现一个事件循环处理,将处理窗口和其构件的事件。
--------------------------------
事件的绑定和处理:
Bind(event,handler,soure = None,id=wx.ID_ANY,id2,wx.ANY)
event 事件类型
handler 事件处理函数
消息对话框 :MessageDialog()
文本输入对话框:TextEntryDialog()
------------------------------------------------
工具栏和状态栏:
每一个WxPython应用程序,都有一个应用程序对象。这个应用程序对象拥有至少一个根窗口,这是WxPython程序的必须部分,另外在应用程序对象中实现一个事件循环处理,将处理窗口和其构件的事件。
import wx
class MyFrame(wx.Frame):
def __init__(self,parent):
wx.Frame.__init__(self,parent,-1,'hello word',size=(300,300))
panel = wx.Panel(self)
size = wx.BoxSizer(wx.VERTICAL)
panel.SetSizer(size)
txt = wx.StaticText(panel,-1,'heelo word')
size.Add(txt,0,wx.TOP|wx.LEFT,100)
self.Centre()
class MyApp(wx.App):
def OnInit(self):
self.frame = MyFrame(None)
self.frame.Show(True)
return True
app = MyApp()
app.MainLoop()
--------------------------------
事件的绑定和处理:
Bind(event,handler,soure = None,id=wx.ID_ANY,id2,wx.ANY)
event 事件类型
handler 事件处理函数
import wx
class MyFrame(wx.Frame):
def click(self,event):
print 'quit'
self.Close()
def __init__(self,parent):
wx.Frame.__init__(self,parent,-1,'hello word',size=(300,300))
panel = wx.Panel(self)
size = wx.BoxSizer(wx.VERTICAL)
panel.SetSizer(size)
txt = wx.StaticText(panel,-1,'heelo word')
size.Add(txt,0,wx.TOP|wx.LEFT,100)
button = wx.Button(panel,-1,"quit")
size.Add(button,0,wx.TOP|wx.LEFT)
self.Bind(wx.EVT_BUTTON, self.click, button, -1, -1)
self.Centre()
class MyApp(wx.App):
def OnInit(self):
self.frame = MyFrame(None)
self.frame.Show(True)
print 'init--',self.frame.GetId()
return True
app = MyApp()
app.MainLoop()
消息对话框 :MessageDialog()
文本输入对话框:TextEntryDialog()
#-*- coding:utf-8 -*-
import wx
class MyFrame(wx.Frame):
def __init__(self,parent):
wx.Frame.__init__(self,parent,-1,'hello word',size=(300,300))
panel = wx.Panel(self)
size = wx.BoxSizer(wx.VERTICAL)
panel.SetSizer(size)
txt = wx.StaticText(panel,-1,'heelo word')
size.Add(txt,0,wx.TOP|wx.LEFT,100)
self.button = wx.Button(panel,-1,"quit")
size.Add(self.button,0,wx.TOP|wx.LEFT)
self.button.Bind(wx.EVT_BUTTON, self.click, self.button, -1, -1)
self.button.Bind(wx.EVT_ENTER_WINDOW, self.enter)
self.button1 = wx.Button(panel,-1,"OK")
self.button1.Bind(wx.EVT_BUTTON, self.ok)
self.Centre()
def enter(self,event):
print 'enter window'
self.button.SetLabel('dddd')
event.Skip()
def click(self,event):
print 'quit'
dlg = wx.MessageDialog(None, u"消息对话框测试", u"标题信息", wx.YES_NO | wx.ICON_QUESTION)
if dlg.ShowModal() == wx.ID_YES:
self.Close(True)
dlg.Destroy()
def ok(self,event):
print 'ok'
text = wx.TextEntryDialog(None,u"请输入文本", u"标题信息")
text.ShowModal()
print text.GetValue()
event.Skip()
#self.Close()
class MyApp(wx.App):
def OnInit(self):
self.frame = MyFrame(None)
self.frame.Show(True)
print 'init--',self.frame.GetId()
return True
app = MyApp()
app.MainLoop()
------------------------------------------------
工具栏和状态栏:
CreateToolBar()
CreateStatusBar()
#-*- coding:utf-8 -*-
import wx
class MyFram(wx.Frame):
def __init__(self,parent):
wx.Frame.__init__(self,parent,-1,u"简单工具栏",size = (800,200))
toolbar = self.CreateToolBar()
toolbar.AddLabelTool(wx.ID_EXIT,'',wx.Bitmap("001.png"))
toolbar.Realize()
self.Bind(wx.EVT_TOOL,self.OnExit,id = wx.ID_EXIT)
self.CreateStatusBar()
self.SetStatusText(u'数据测试')
self.Center()
def OnExit(self,event):
self.Close()
app = wx.App()
frame = MyFram(None)
frame.Show()
app.MainLoop()