wxPython – wx.StatusBar 中的 SetStatusWidths()函数
在本文中,我们将学习与 wxPython 的 wx.StatuBar 类关联的 SetStatusWidths()函数。 SetStatusWidths()函数设置状态行中字段的宽度。
有两种类型的字段:固定宽度和可变宽度字段。对于固定宽度的字段,您应该以像素为单位指定它们的(恒定)宽度。对于可变宽度字段,指定一个负数,指示字段应如何扩展:所有可变宽度字段的剩余空间根据该数字的绝对值在它们之间划分。宽度为 -2 的可变宽度字段获得的宽度是宽度为 -1 的字段的两倍,依此类推。
Syntax: wx.StatuBar.SetStatusWidths(self, widths)
Parameters:
Parameter | Input Type | Description |
---|---|---|
widths | list of ints | The text to be set. Use an empty string (“”) to clear the field. |
i | int | Contains an array of n integers, each of which is either an absolute status field width in pixels if positive or indicates a variable width field if negative. The special value None means that all fields should get the same width. |
代码示例:
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))
self.statusbar.SetFieldsCount(3)
# SET WIDTHS FOR CORRESPONDING FIELD
self.statusbar.SetStatusWidths([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.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()
输出窗口: