📜  wxPython - 创建具有不同方向的项目的单选框

📅  最后修改于: 2022-05-13 01:54:30.109000             🧑  作者: Mango

wxPython - 创建具有不同方向的项目的单选框

在本文中,我们将学习如何创建一个单选框,其中包含水平和垂直方向的项目。为此,我们将在创建单选框时使用样式参数。

Radio Box中有两种样式。

  • wx.RA_SPECIFY_ROWS:主要维度参数是指最大行数。
  • wx.RA_SPECIFY_COLS:主要维度参数是指最大列数。

代码示例:

Python3
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 radio box with items in horizontal orientation
        self.rbox = wx.RadioBox(pnl, label ='RadioBox', pos =(10, 10), choices = hlist,
                                majorDimension = 0, style = wx.RA_SPECIFY_ROWS)
 
        # create radio box with items in vertical orientation
        self.rbox = wx.RadioBox(pnl, label ='RadioBox', pos =(240, 10), choices = vlist,
                                majorDimension = 0, style = wx.RA_SPECIFY_COLS)
        # 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()


输出窗口: