wxPython – wx.Button 中的 Create()函数
在本文中,我们将学习与 wxPython 的 wx.Button 类关联的 Clear()函数。 Create()函数用于两步创建的按钮创建函数。
它将按钮的属性作为参数。
Syntax: wx.Button.Create(self, parent, id=ID_ANY, label=””, pos=DefaultPosition, size=DefaultSize, style=0, validator=DefaultValidator, name=ButtonNameStr)
Parameters:
Parameter | Input Type | Description |
---|---|---|
parent | wx.Window | Parent window. Should not be None. |
id | wx.WindowID | Control identifier. A value of -1 denotes a default value. |
label | string | Text Label. |
pos | wx.Point | Window position. |
size | wx.Window | Window size. |
style | long | Window style. |
validator | wx.Validator | Window validator. |
name | string | Window name. |
Return Type: bool
代码示例:
import wx
class Example(wx.Frame):
def __init__(self, *args, **kwargs):
super(Example, self).__init__(*args, **kwargs)
self.InitUI()
def InitUI(self):
self.pnl = wx.Panel(self)
self.btn = wx.Button()
# CREATE BUTTON USING Create() function FOR TWO STEP CREATION
self.btn.Create(self.pnl, label ='Button', pos =(20, 20))
self.SetSize((350, 250))
self.SetTitle('wx.Button')
self.Centre()
def main():
app = wx.App()
ex = Example(None)
ex.Show()
app.MainLoop()
if __name__ == '__main__':
main()
输出窗口: