wxpython核心部件之wx.button
wx.Button 是一个简单部件. 它包含了一个文本字符串. 用于激发 (trigger) 一个动作.
专题教程:wxpython中文教程
wx.Button 样式:
例子:
#!/usr/bin/python
#coding=utf-8
# www.plcxue.com
#buttons.py
import wx, random
APP_SIZE_X = 300
APP_SIZE_Y = 200
class MyButtons(wx.Dialog):
def __init__(self, parent, id, title):
wx.Dialog.__init__(self, parent, id, title, size=(APP_SIZE_X, APP_SIZE_Y))
wx.Button(self, 1, '关闭', (50, 130))
wx.Button(self, 2, '随机移动', (150, 130), (110, -1))
self.Bind(wx.EVT_BUTTON, self.OnClose, id=1)
self.Bind(wx.EVT_BUTTON, self.OnRandomMove, id=2)
self.Center()
self.ShowModal()
self.Destroy()
def OnClose(self, event):
self.Close(True)
def OnRandomMove(self, evnet):
screensize = wx.GetDisplaySize()
randx = random.randrange(0, screensize.x - APP_SIZE_X)
randy = random.randrange(0, screensize.y - APP_SIZE_Y)
self.Move((randx, randy))
app = wx.App(0)
MyButtons(None, -1, 'buttons.py')
app.MainLoop()
如图:
图:buttons.py