在本文中,我們將學習與wxPython的wx.RadioBox類關聯的GetItemFromPoint()函數。 GetItemFromPoint()函數用於簡單地返回該點下的單選框項目,從零開始的項目索引;如果該點下沒有任何項目,則返回NOT_FOUND。
它以客戶端點為參數。
用法: wx.RadioBox.GetItemFromPoint(self, pt)
參數:
參數 | 輸入類型 | 描述 |
---|---|---|
pt | wx.Point | 指向客戶坐標。 |
返回類型:整型
代碼示例:
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
輸出窗口:
相關用法
- wxPython wx.StaticText IsEllipsized()用法及代碼示例
- wxPython wx.StaticText GetBackgroundColour()用法及代碼示例
- wxPython wx.ToolBar InsertSeparator()用法及代碼示例
- wxPython GetClassDefaultAttributes()用法及代碼示例
- wxPython wx.StaticText SetBackgroundColour()用法及代碼示例
- wxPython wx.Button SetBitmapPosition()用法及代碼示例
- wxPython wx.StaticText GetLabel()用法及代碼示例
- wxPython FindControl()用法及代碼示例
- wxPython FindToolForPosition()用法及代碼示例
- wxPython wx.StaticText SetForegroundColour()用法及代碼示例
注:本文由純淨天空篩選整理自RahulSabharwal大神的英文原創作品 wxPython – GetItemFromPoint() function in wx.RadioBox。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。