1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | import wx class Example(wx.Frame): def __init__( self , * args, * * kwargs): super (Example, self ).__init__( * args, * * kwargs) self .InitUI() def InitUI( self ): self .count = 5 self .toolbar = self .CreateToolBar() tundo = self .toolbar.AddLabelTool(wx.ID_UNDO, ' ', wx.Bitmap(' img / blogger.png')) tredo = self .toolbar.AddLabelTool(wx.ID_REDO, ' ', wx.Bitmap(' img / youtube.png')) self .toolbar.EnableTool(wx.ID_REDO, False ) self .toolbar.AddSeparator() texit = self .toolbar.AddLabelTool(wx.ID_EXIT, ' ', wx.Bitmap(' img / icon_shortcut_tickets.png')) self .toolbar.Realize() self .Bind(wx.EVT_TOOL, self .OnQuit, texit) self .Bind(wx.EVT_TOOL, self .OnUndo, tundo) self .Bind(wx.EVT_TOOL, self .OnRedo, tredo) self .SetSize(( 250 , 200 )) self .SetTitle( 'Undo redo' ) self .Centre() self .Show( True ) def OnUndo( self , e): if self .count > 1 and self .count < = 5 : self .count = self .count - 1 if self .count = = 1 : self .toolbar.EnableTool(wx.ID_UNDO, False ) if self .count = = 4 : self .toolbar.EnableTool(wx.ID_REDO, True ) def OnRedo( self , e): if self .count < 5 and self .count > = 1 : self .count = self .count + 1 if self .count = = 5 : self .toolbar.EnableTool(wx.ID_REDO, False ) if self .count = = 2 : self .toolbar.EnableTool(wx.ID_UNDO, True ) def OnQuit( self , e): self .Close() def main(): ex = wx.App() Example( None ) ex.MainLoop() if __name__ = = '__main__' : main() |
article
Sunday, May 27, 2018
wxpython enable and disable toolbar buttons
wxpython enable and disable toolbar buttons