wxPython – wx.StatusBar 中的 SetStatusStyles()函数
在本文中,我们将学习与 wxPython 的 wx.StatusBar 类关联的 SetStatusStyles()函数。 SetStatusStyles()函数设置状态行中字段的样式,可以使字段显示为平坦或凸起,而不是标准的凹陷 3D 边框。
它需要一个包含 n 个整数的数组,其中每个字段的样式作为参数。
Syntax: wx.StatusBar.SetStatusStyles(Self, styles)
Parameters:
Parameter Input Type Description styles list of int Contains an array of n integers with the styles for each field.
There are four possible styles:
1. SB_NORMAL (default): The field appears with the default native border.
2. SB_FLAT: No border is painted around the field so that it appears flat.
3. SB_RAISED: A raised 3D border is painted around the field.
4. SB_SUNKEN: A sunken 3D border is painted around the field (this style is new since wxWidgets 2.9.5).
代码示例:
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)
self.statusbar = wx.StatusBar()
self.statusbar.Create(self, id = 1, name = "Status Bar")
self.SetStatusBar(self.statusbar)
self.SetSize((350, 250))
# SET TOTAL NUMBER OF FIELDS AND RESPECTIVE WIDTHS
self.statusbar.SetFieldsCount(3, [100, 80, 60])
# SET TEXT FOR ALL FIELDS
self.statusbar.SetStatusText("Field One", 0)
self.statusbar.SetStatusText("Field Two", 1)
self.statusbar.SetStatusText("Field Three", 2)
self.statusbar.SetBackgroundColour((200, 188, 73, 243))
# SET STYLES FOR ALL STATUS FIELDS
self.statusbar.SetStatusStyles([wx.SB_FLAT, wx.SB_SUNKEN, wx.SB_RAISED])
self.SetTitle('New Frame Title')
self.Centre()
print(self.statusbar.GetMinHeight())
def main():
app = wx.App()
ex = Example(None)
ex.Show()
app.MainLoop()
if __name__ == '__main__':
main()
输出窗口: