在本文中,我们将学习与wxPython的wx.MenuItem类关联的IsChecked()函数。如果启用该项目,则IsEnabled()返回True。
IsEnabled()函数中不需要任何参数。
用法:
wx.MenuItem.IsEnabled(self)
参数:
No parameters are required in IsEnabled() function.
返回类型:
bool
代码示例:
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.item = wx.MenuItem(self.fileMenu, 1, '&Check', helpString ="Check Help", kind = wx.ITEM_CHECK)
self.item.SetBitmap(wx.Bitmap('right.png'))
self.item.SetTextColour((79, 81, 230, 255))
self.item.Enable(True)
self.st = wx.StaticText(self, label ="", pos =(200, 200))
self.fileMenu.Append(self.item)
self.menubar.Append(self.fileMenu, '&File')
self.SetMenuBar(self.menubar)
if self.item.IsEnabled()== True:
# print if item is enable
print("Item is Enabled")
else:
# print if item is disabled
print("Item is Disabled")
self.SetSize((350, 250))
self.SetTitle('Icons and shortcuts')
self.Centre()
def main():
app = wx.App()
ex = Example(None)
ex.Show()
app.MainLoop()
if __name__ == '__main__':
main()
输出:
Item is Enabled
代码示例:
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.item = wx.MenuItem(self.fileMenu, 1, '&Check', helpString ="Check Help", kind = wx.ITEM_CHECK)
self.item.SetBitmap(wx.Bitmap('right.png'))
self.item.SetTextColour((79, 81, 230, 255))
# Disable the item
self.item.Enable(False)
self.st = wx.StaticText(self, label ="", pos =(200, 200))
self.fileMenu.Append(self.item)
self.menubar.Append(self.fileMenu, '&File')
self.SetMenuBar(self.menubar)
if self.item.IsEnabled()== True:
# print if item is enable
print("Item is Enabled")
else:
# print if item is disabled
print("Item is Disabled")
self.SetSize((350, 250))
self.SetTitle('Icons and shortcuts')
self.Centre()
def main():
app = wx.App()
ex = Example(None)
ex.Show()
app.MainLoop()
if __name__ == '__main__':
main()
输出:
Item is Disabled
相关用法
- wxPython wx.MenuBar IsEnabled()用法及代码示例
- wxPython wx.Button GetClassDefaultAttributes()用法及代码示例
- wxPython wx.ToolBar InsertTool()用法及代码示例
- wxPython wx.StatusBar SetStatusStyles()用法及代码示例
- wxPython wx.ToolBar InsertStretchableSpace()用法及代码示例
- wxPython wx.Button GetDefaultSize()用法及代码示例
- wxPython wx.Button SetLabel()用法及代码示例
- wxPython wx.StaticText Create()用法及代码示例
- wxPython wx.ToolBar GetToolShortHelp()用法及代码示例
- wxPython wx.StaticText SetForegroundColour()用法及代码示例
注:本文由纯净天空筛选整理自RahulSabharwal大神的英文原创作品 wxPython – IsEnabled() function in wx.MenuItem。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。