按钮控件
来源:互联网 发布:西科软件招聘 编辑:程序博客网 时间:2024/04/29 16:49
普通按钮
# -*- coding: UTF-8 -*-import wxclass ButtonFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, u'按钮', size=(300, 90)) #父类构造函数 panel = wx.Panel(self, -1) self.button = wx.Button(panel, -1, u"确定", pos=(10, 10)) # 创建按钮对象,按钮标签为中文“确定”故前加u self.Bind(wx.EVT_BUTTON, self.OnClick, self.button) #为按钮绑定onclick事件处理函数 self.button.SetDefault() # 设置button为默认按钮 self.inputText = wx.TextCtrl(panel, -1, "", pos = (100,10), size=(150, -1), style=wx.TE_READONLY) #style=wx.TE_READONLY 表示创建只读文本框控件 def OnClick(self, event): #event表示单击 self.inputText.Value = "Hello world!" #单击确定时,只读文本框inputText将出现值"Hello worldif __name__ == '__main__': app = wx.PySimpleApp() frame = ButtonFrame() frame.Show() app.MainLoop()
效果,单击确定,文本框显示helloworld
位图按钮
创建位图按钮前要确定image类型的格式,并将其转换位bitmap类型,再创建位图按钮,并关联bitmap的实例化对象
import wxclass BitmapButtonFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, u'位图按钮', size=(200, 150)) panel = wx.Panel(self, -1) bmp = wx.Image("button.png", wx.BITMAP_TYPE_PNG).ConvertToBitmap() #bmp为wx.Image的对象。 wx.Image("button.png", wx.BITMAP_TYPE_PNG)表示图片类型为PNG格式 #ConvertToBitmap()将image转换为Bitmap类型对象 self.button = wx.BitmapButton(panel, -1, bmp, pos=(20, 20), size=(120, 60)) #创建BitmapButton类的对象button,并关联了前面的bmp对象 self.Bind(wx.EVT_BUTTON, self.OnClick, self.button) #设置了按钮单击事件和处理函数OnClick self.button.SetDefault() def OnClick(self, event): wx.MessageBox("Hello world!", u"提示") #单击按钮后弹出对话框 内容为Hello world!。对话框标题为“提示”if __name__ == '__main__': app = wx.PySimpleApp() frame = BitmapButtonFrame() frame.Show() app.MainLoop()
结果:单击位图
0 0
- 按钮控件
- 按钮控件
- 按钮控件
- 控件,按钮
- 按钮控件
- 按钮控件
- 按钮控件
- 自定义按钮控件-图标按钮
- 自定义按钮控件-热点按钮
- 自定义按钮控件-圆形按钮
- MFC----windows控件----按钮控件
- 自定义控件--图片按钮
- 按钮控件(button)
- 按钮控件使能
- HtmlInputButton 按钮控件
- HtmlInputRadio 收音机按钮控件
- 按钮控件添加位图
- 设置按钮控件字体
- HDU1242-Rescue
- spoj 375 Query on a tree(树链剖分模版)
- 设计模式の面向对象
- JSP 页面实现文件上传
- 杨昌英诉张世雄子女抚养及财产分割纠纷案
- 按钮控件
- HDU - 4944 FSF’s game
- Single Round Match
- cocos2dx3.2 学习笔记(3)--ActionsEaseTest(1)
- 贪心算法 摘记
- Android设计模式--适配器模式
- OBEX浅析
- java.lang.NoClassDefFoundError
- git 打patch方法