【C】wxPython中简单界面设计-按钮

1. 安装好wxPython

2.编写程序哈哈哈哈哈哈

import wx
class ButtonFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self,None,-1,"ButtonFrame",size=(500,200))
        panel = wx.Panel(self,-1)
        self.button = wx.Button(panel,-1,"Hello",pos=(10,20))
        self.Bind(wx.EVT_BUTTON,self.OnClick,self.button) # Bind(event,handler,soure = None,id=wx.ID_ANY,id2,wx.ANY)
        self.button.SetDefault()

    def OnClick(self, event):
        self.button.SetLabel("Clicked")# when clicked,button label changed to "Clicked"
if __name__ == '__main__':
    app = wx.App()# create an APP,every wxpython is a living example,if you want a complex APP,use "class" to extend
    frame = ButtonFrame() # complicate is "wx.Frame(parent,ID,title)",;ID is -1 default;
    frame.Show()# show the Frame
    app.MainLoop()# run the APP

class中定义比较复杂的函数

wx.Frame原型

Frame(parent, id=ID_ANY, title="", pos=DefaultPosition, size=DefaultSize, style=DEFAULT_FRAME_STYLE, name=FrameNameStr)

Panel是面板,wx.Button增加一个按钮

Bind()连接事件,原型wx.Frame.Bind(self, event, handler, source=None, id=-1, id2=-1)

基本上只会给定event、handler和source,event是事件的名称,handler是处理函数,source是事件的发生者,self.Bind(wx.EVT_BUTTON, self.OnButton1, self.Button1)表示的是:一个Button1被单击而发生了EVT_BUTTON事件,用self.OnButton1()来处理,self.OnButton1()是事件处理函数

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值