在本文中,我們將學習與wxPython的wx.MenuItem類關聯的IsSubMenu()函數。如果該項目是子菜單,則IsSubMenu()函數僅返回True,如果該項目不是子菜單,則返回False。
IsSubMenu()函數不需要任何參數。
用法:
wx.MenuItem.IsSubMenu(self)
參數:
No parameters are required by IsSubMenu() function.
返回類型:
bool
代碼示例:
import wx
class Example(wx.Frame):
def __init__(self, *args, **kwargs):
super(Example, self).__init__(*args, **kwargs)
self.InitUI()
def InitUI(self):
menubar = wx.MenuBar()
fileMenu = wx.Menu()
sm = wx.Menu()
sm.Append(wx.ID_ANY, 'Submenu item 1')
sm.Append(wx.ID_ANY, 'Submenu item 2')
sm.Append(wx.ID_ANY, 'Submenu item 3')
item = wx.MenuItem(fileMenu, 1, '&Check\tCtrl + c', helpString ="Check Help")
item.SetSubMenu(sm)
fileMenu.AppendMenu(wx.ID_ANY, 'I&mport', sm)
n = item.IsSubMenu()
# if item is sub menu
if(n == True):
print("Item is SubMenu Item")
else:
print("Item is not a SubMenu Item")
menubar.Append(fileMenu, '&File')
self.SetMenuBar(menubar)
self.SetSize((350, 250))
self.SetTitle('Submenu')
self.Centre()
def main():
app = wx.App()
ex = Example(None)
ex.Show()
app.MainLoop()
if __name__ == '__main__':
main()
輸出:
Item is SubMenu Item.
輸出窗口:
相關用法
- wxPython wx.MenuItem GetTextColour()用法及代碼示例
- wxPython wx.RadioButton Enable()用法及代碼示例
- wxPython wx.MenuItem SetSubMenu()用法及代碼示例
- wxPython wx.MenuItem SetMenu()用法及代碼示例
- wxPython wx.RadioBox FindString()用法及代碼示例
- wxPython wx.StatusBar SetStatusText()用法及代碼示例
- wxPython wx.Toolbar EnableTool()用法及代碼示例
- wxPython wx.ToolBar Realize()用法及代碼示例
注:本文由純淨天空篩選整理自RahulSabharwal大神的英文原創作品 wxPython – IsSubMenu() function in wx.MenuItem。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。