wxPython 静态框
在本文中,我们将学习 wxPython 中的静态框。静态框是围绕其他窗口绘制的矩形,用于表示项目的逻辑分组。
请注意,虽然以前的版本要求将出现在静态框内的窗口创建为其兄弟(即使用与静态框本身相同的父级),但从 wxWidgets 2.9.1 开始,也可以将它们创建为 wx.StaticBox 的子级如果与以前版本的兼容性并不重要,那么实际上鼓励您这样做。
Syntax: wx.StaticBox.StaticBox((parent, id=ID_ANY, label=””, pos=DefaultPosition, size=DefaultSize, style=0, name=StaticBoxNameStr)
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. |
label | string | Text to be displayed in the static box, the empty string for no label. |
pos | wx.Point | Window position. If wx.DefaultPosition is specified then a default position is chosen. |
size | wx.Size | Checkbox size. If wx.DefaultSize is specified then a default size is chosen. |
style | long | Window style. There are no StaticBox-specific styles, but generic ALIGN_LEFT, ALIGN_CENTRE_HORIZONTAL and ALIGN_RIGHT can be used here to change the position of the static box label when using wxGTK |
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)
# create static box
self.sb = wx.StaticBox(pnl, 2, label ="Static Box",
pos =(20, 20), size =(100, 100))
# 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()
输出窗口: