wxPython 使用Create()函数的静态线

wxPython 使用Create()函数的静态线

在这篇文章中,我们将学习与wxPython的wx.StaticLine类相关的Create()方法。静态线就是在对话框中用来分隔各组控件的线。Create()函数通过两步创建静态线。

线条可以是垂直或水平的。此外,并不是所有的端口(特别是wxGTK)都支持指定线的横向方向(例如,水平线的高度),所以为了最大限度的移植,你应该把它指定为DefaultCoord。

语法:wx.StaticLine.Create(parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize, style=LI_HORIZONTAL, name=StaticLineNameStr)

参数

参数 输入类型 说明
parent wx.Window 父窗口。必须不是无。
id wx.WindowID 窗口标识符。值wx.ID_ANY表示一个默认值。
pos wx.Point 窗口的位置。如果指定了wx.DefaultPosition,那么将选择一个默认位置。
size wx.Size 尺寸。注意,高度或宽度(取决于线条是水平还是垂直)会被忽略。
style 窗口风格(wx.LI_HORIZONTAL或wx.LI_VERTICAL)。
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']
  
        # initialize a static line
        self.sl = wx.StaticLine()
  
        # add attributes using Create()  function
        self.sl.Create(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()

输出窗口。

wxPython - 使用Create()函数的静态线

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程

wxPython 教程