wxPython – wx.StaticLine 中的 StaticLine() 构造函数
在本文中,我们将学习与 wxPython 的 wx.StaticLine 类关联的 StaticLine() 构造函数。静态线只是可以在对话框中用于分隔控件组的线。
该线可能只是垂直或水平的。此外,并非所有端口(尤其不是 wxGTK)都支持指定线的横向方向(例如水平线的高度),因此为了获得最大的可移植性,您应该将其指定为 DefaultCoord。
Syntax: wx.StaticLine.StaticLine(parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize, style=LI_HORIZONTAL, name=StaticLineNameStr)
Parameters
Parameter | Input Type | Description |
---|---|---|
parent | wx.Window | Parent window. Must not be None. |
id | wx.WindowID | Window identifier. The value wx.ID_ANY indicates a default value. |
pos | wx.Point | Window position. If wx.DefaultPosition is specified then a default position is chosen. |
size | wx.Size | Size. Note that either the height or the width (depending on whether the line if horizontal or vertical) is ignored. |
style | long | Window style (either wx.LI_HORIZONTAL or wx.LI_VERTICAL). |
name | string | Window Name |
代码示例:
import wx
class FrameUI(wx.Frame):
def __init__(self, parent, title):
super(FrameUI, self).__init__(parent, title = title, size =(300, 200))
# function for in-frame components
self.InitUI()
def InitUI(self):
# parent panel for radio box
pnl = wx.Panel(self)
# list of choices
hlist = ['Item One', 'Item Two']
vlist =['Item One', 'Item Two']
# create vertical line from point (50, 0) t0 (50, 250)
self.sl = wx.StaticLine(pnl, 2, pos =(50, 0), size = (1, 250),
style = wx.LI_VERTICAL)
# set frame in centre
self.Centre()
# set size of frame
self.SetSize((400, 250))
# show output frame
self.Show(True)
# wx App instance
ex = wx.App()
# Example instance
FrameUI(None, 'RadioButton and RadioBox')
ex.MainLoop()
输出窗口: