wxPython – wx.StatusBar 中的 Create()函数
在本文中,我们将学习与 wxPython 的 wx.StatusBar 类关联的 Create()函数。与 StatusBar() 构造函数类似,Create 用于向状态栏添加属性,提供状态栏变量应使用 StatusBar() 构造函数初始化,不带任何参数。
Create 将状态栏的属性作为参数。
Syntax: wx.StatusBar.Create(self, parent, id=ID_ANY, style=STB_DEFAULT_STYLE, name=StatusBarNameStr)
Parameters: Parameter Input Type Description parent wx.Frame Parent Frame to attach statusbar to. id int Identifier to be used for statusbar. style long Style of the status bar. name string Name associated with statusbar.
代码示例:
Python3
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)
# INITIALIZE USING EMPTY CONSTRUCTOR
self.statusbar = wx.StatusBar()
# CREATE STATUS BAR USING CREATE FUNCTION
self.statusbar.Create(self, id = 1, style = wx.STB_DEFAULT_STYLE,
name = "Status Bar")
self.statusbar.SetStatusText("Hello there this is a Status Bar")
self.SetStatusBar(self.statusbar)
self.SetSize((350, 250))
self.SetTitle('New Frame Title')
self.Centre()
def main():
app = wx.App()
ex = Example(None)
ex.Show()
app.MainLoop()
if __name__ == '__main__':
main()
输出窗口: