wxPython – wx.StaticText 中的 Create()函数
在本文中,我们将学习与 wxPython 的 wx.StaticText 类关联的 Create()。静态文本控件显示一行或多行只读文本。
Create()函数用于两步创建静态文本。我将 statictext 的属性作为参数。
Syntax: wx.StaticText.Create(parent, id=ID_ANY, label=””, pos=DefaultPosition, size=DefaultSize, style=0, name=StaticTextNameStr)
Parameters:
Parameter | Input Type | Description |
---|---|---|
parent | wx.Window | Parent window. Should not be None. |
id | wx.Window | Parent window. Should not be None. |
parent | wx.WindowID | Control identifier. A value of -1 denotes a default value. |
label | string | Text label. |
pos | wx.Point | Window position. |
size | wx.Size | Window size. |
style | long | Window style. |
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.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
self.pnl = wx.Panel(self)
bmp = wx.Bitmap('right.png')
self.st = wx.StaticText()
# CREATE STATICTEXT AT POINT (20, 20) USING Create() FUNCTION
self.st.Create(self.pnl, id = 1, label ="This is StaticText", pos =(20, 20),
size = wx.DefaultSize, style = 0, name ="statictext")
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()
输出窗口: