在本文中,我們將學習與wxPython的wx.MenuBar類關聯的IsEnabled()函數。 IsEnabled()函數很有用,因為它確定是否啟用了一項。如果找到並啟用了該項目,則IsEnabled()函數返回True,否則返回False。
用法: wx.MenuBar.IsEnabled(self, id)
參數:
參數 | 輸入類型 | 描述 |
---|---|---|
id | int | 菜單項標識符。 |
代碼示例:
import wx
class Example(wx.Frame):
def __init__(self, *args, **kwargs):
super(Example, self).__init__(*args, **kwargs)
self.InitUI()
def InitUI(self):
self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
self.menubar = wx.MenuBar()
self.fileMenu = wx.Menu()
self.fileMenu2 = wx.Menu()
self.item = wx.MenuItem(self.fileMenu, 1, '&Check', helpString ="Check Help",
kind = wx.ITEM_CHECK)
self.item.SetBitmap(wx.Bitmap('right.png'))
self.fileMenu.Append(self.item)
# DISABLE MENU ITEM
self.item.Enable(False)
self.menubar.Append(self.fileMenu, '&File')
self.SetMenuBar(self.menubar)
self.SetSize((350, 250))
self.SetTitle('New Frame Title')
self.Centre()
if(self.menubar.IsEnabled(1)== True):
# print CLICKABLE if True
print("CLICKABLE")
else:
# else print UNCLICKABLE
print("UNCLICKABLE")
def main():
app = wx.App()
ex = Example(None)
ex.Show()
app.MainLoop()
if __name__ == '__main__':
main()
輸出:
控製台輸出:
UNCLICKABLE
相關用法
- wxPython wx.MenuItem IsEnabled()用法及代碼示例
- wxPython wx.Button SetDefault()用法及代碼示例
- wxPython wx.MenuItem SetBackgroundColour()用法及代碼示例
- wxPython wx.ToolBar SetDropdownMenu()用法及代碼示例
- wxPython wx.Button SetAuthNeeded()用法及代碼示例
- wxPython wx.MenuItem IsSubMenu()用法及代碼示例
- wxPython wx.MenuItem IsSeparator()用法及代碼示例
- wxPython wx.ToolBar InsertSeparator()用法及代碼示例
- wxPython wx.MenuBar IsChecked()用法及代碼示例
- wxPython wx.StaticText SetBackgroundColour()用法及代碼示例
- wxPython wx.MenuBar Attach()用法及代碼示例
注:本文由純淨天空篩選整理自RahulSabharwal大神的英文原創作品 wxPython – IsEnabled() function in wx.MenuBar。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。