wxPython – wx.RadioBox 中的 GetItemFromPoint()函数
在本文中,我们将学习与 wxPython 的 wx.RadioBox 类关联的 GetItemFromPoint()函数。 GetItemFromPoint()函数用于简单地返回该点下的单选框项目、从零开始的项目索引,或者如果该点下没有项目,则返回 NOT_FOUND。
它将客户点作为参数。
Syntax: wx.RadioBox.GetItemFromPoint(self, pt)
Parameters:
Parameter | Input Type | Description |
---|---|---|
pt | wx.Point | Point in client coordinates. |
Return Type: int
代码示例:
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
lblList = ['Radio One', 'Radio Two']
# create radio boc containing above list
self.rbox = wx.RadioBox(pnl, label ='RadioBox', pos =(80, 10), choices = lblList,
majorDimension = 1, style = wx.RA_SPECIFY_COLS)
# print item at point (80, 30)
print (self.rbox.GetItemFromPoint((80, 30)))
# 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()
控制台输出:
0
输出窗口: