Python GUI设计 PythonWx

WxPython 应用程序组成:
每一个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()


  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Car12

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值