Python Forum
General help with hide show status bar for a begineer in python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
General help with hide show status bar for a begineer in python
#1
Hi guys!
I have the following code, everything is working, except that I can't get the function for hiding the tool bar to work. Originally I was using a different approach from a tutorial, it was working, but now that I added new things and changed some old, I get a problem.
error: AttributeError: 'Example' object has no attribute 'toolbar'
I tried changing the function "toolbar.Hide()" with "toolbar = toolbar.Hide()" and "toolbar = Hide()" and a few other things, but it does not work. Can someone explain to me the difference between the 2 approaches and how to fix the problem?

Also a good python function reference would be good.

Thanks in advance!

Important part of the code, new appraoch:
                                            #Toolbar block.
        toolbar = self.CreateToolBar()#Visual creation of the toolbar.
        QuitTool = toolbar.AddTool(wx.ID_ANY, 'Exit', wx.Bitmap('exit.png'))#Adding picture to the toolbar button.
        OpenTool = toolbar.AddTool(wx.ID_ANY, 'Open', wx.Bitmap('o.png'))#Adding picture to the toolbar button.
        toolbar.Realize()

        self.Bind(wx.EVT_TOOL, self.OnQuit, QuitTool)#Adding operation to the toolbar button.
        self.Bind(wx.EVT_TOOL, self.OnQuit, OpenTool)#Adding operation to the toolbar button.
        ..........................
        def ToggleToolBar(self, e):#Function for the menu function block. Different toolbar. For ticking on/of the toolbar.
        if self.shtl.IsChecked():
            toolbar.Show()
        else:
            toolbar.Hide()       
Important part of the code old approach.
        self.toolbar = self.CreateToolBar()#Visual creation of the toolbar.
        self.toolbar.AddTool(1, '', wx.Bitmap('exit.png'))#Adding picture to the toolbar button.
        self.toolbar.Realize()#Adding operation to the toolbar button.
        .........................
        def ToggleToolBar(self, e):#Function for the menu function block.
        if self.shtl.IsChecked():
            self.toolbar.Show()
        else:
            self.toolbar.Hide()
Full code, new approach:
#!/usr/bin/env python3  #Settings.
# -*- coding: utf-8 -*- #Encoding of the source code.
 
# simple.py #Name of the file.


import wx

APP_EXIT = 1#ID
APP_SECOND = 2#ID
                            #Context menu visual and operation creation.
class MyPopupMenu(wx.Menu):

    def __init__(self, parent):
        super(MyPopupMenu, self).__init__()

        self.parent = parent
                                                        #Minimize block.
        mmi = wx.MenuItem(self, wx.NewId(), 'Minimize')
        self.Append(mmi)
        self.Bind(wx.EVT_MENU, self.OnMinimize, mmi)
                                                    #Close block.
        cmi = wx.MenuItem(self, wx.NewId(), 'Close')
        self.Append(cmi)
        self.Bind(wx.EVT_MENU, self.OnClose, cmi)
                                                #Custom block.
        Custom = wx.MenuItem(self, wx.NewId(), 'Do')#Create the visual style.
        self.Append(Custom)#Add the visual style to the context menu.
        self.Bind(wx.EVT_MENU, self.OnDo, Custom)#Add the operation to the context menu item.
        
    def OnMinimize(self, e):#Minimize operation
        self.parent.Iconize()

    def OnClose(self, e):#Close operation
        self.parent.Close()
        
    def OnDo(self, e):#Custom operation
        self.parent.Close()

class Example(wx.Frame):#"wx.Frame" is turned into a class.
    
    def __init__(self, *args, **kwargs):#???Initialization???
        super(Example, self).__init__(*args, **kwargs)

        self.InitUI()

    def InitUI(self):#Main features.
        self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
        menubar = wx.MenuBar()
        viewMenu = wx.Menu()
                                                                #Menu visual button creation block.
                                                                #Example: ID = viewMenu.Append(wx.ID_ANY, 'Name', 'Name', kind=wx.TYPE_OF_MENU)
        self.shst = viewMenu.Append(wx.ID_ANY, 'Show statusbar',
            'Show Statusbar', kind=wx.ITEM_CHECK)#Add a check item. Parameters can be used for any type of menu command. The ID only has to be different.
        self.shtl = viewMenu.Append(wx.ID_ANY, 'Show toolbar',
            'Show Toolbar', kind=wx.ITEM_CHECK)#Add a check item. Parameters can be used for any type of menu command. The ID only has to be different.
        self.quit = viewMenu.Append(wx.ID_ANY, 'Exit',
            'Exit', kind=wx.ITEM_CHECK)#Add a check item. Parameters can be used for any type of menu command. The ID only has to be different.
                                               #Menu button additional functions block.
        viewMenu.Check(self.shst.GetId(), True)#Add a tick possibility to the menu option. Function is on, when the tick is on.
        viewMenu.Check(self.shtl.GetId(), True)#Add a tick possibility to the menu option. Function is on, when the tick is on.
                                                                #Menu function block.
        self.Bind(wx.EVT_MENU, self.ToggleStatusBar, self.shst)#Specify which funtion to be performed when the menu is ticked on/off.
        self.Bind(wx.EVT_MENU, self.ToggleToolBar, self.shtl)#Specify which funtion to be performed when the menu is ticked on/off.
        self.Bind(wx.EVT_MENU, self.OnQuit, self.quit)#Specify which funtion to be performed when the menu is ticked on/off. This menu has no tick option, it will only work once for off,
                                                      #no on option by putting the tick again is possible, because "viewMenu.Chech()" is not added for it. For "EXIT" its not needed.

        menubar.Append(viewMenu, '&Menu')#Name of the menu button shown in the up toolbar.
        self.SetMenuBar(menubar)
                                            #Toolbar block.
        toolbar = self.CreateToolBar()#Visual creation of the toolbar.
        QuitTool = toolbar.AddTool(wx.ID_ANY, 'Exit', wx.Bitmap('exit.png'))#Adding picture to the toolbar button.
        OpenTool = toolbar.AddTool(wx.ID_ANY, 'Open', wx.Bitmap('o.png'))#Adding picture to the toolbar button.
        toolbar.Realize()

        self.Bind(wx.EVT_TOOL, self.OnQuit, QuitTool)#Adding operation to the toolbar button.
        self.Bind(wx.EVT_TOOL, self.OnQuit, OpenTool)#Adding operation to the toolbar button.
                                                #Status bar block.
        self.statusbar = self.CreateStatusBar()#Visual creation of the statusbar.
        self.statusbar.SetStatusText('Ready')#Default text displayed in the statusbar.
                                #Program size/title/position block.
        self.SetSize((350, 250))#Set the program size.
        self.SetTitle('Toolbox')#Set the program title in the upest bar.
        self.Centre()#The program will start in the center of the screen.
                                                    #Context menu block.
        self.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)#On "RightDown"(right-click) event, do RightDown operation.

    def OnRightDown(self, e):#Context menu right click operation.#Operation RightDown.
        self.PopupMenu(MyPopupMenu(self), e.GetPosition())#Menu to be shown=MyPopupMenu(self), Position to be shown=e.GetPosition.

    def ToggleStatusBar(self, e):#Function for the menu function block.

        if self.shst.IsChecked():
            self.statusbar.Show()
        else:
            self.statusbar.Hide()

    def ToggleToolBar(self, e):#Function for the menu function block. Different toolbar. For ticking on/of the toolbar.

        if self.shtl.IsChecked():
            self.toolbar.Show()
        else:
            self.toolbar.Hide()
        
    def OnQuit(self, e):#Function for the menu function block.
        self.Close()


def main():

    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()


if __name__ == '__main__':
    main()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Hide clicked buttons Rubberduck 6 3,446 Jun-02-2021, 12:44 PM
Last Post: Rubberduck
  [PyQt] Hide Dock Icon for QSystemTrayIcon App AeglosGreeenleaf 0 3,264 Jun-20-2019, 07:21 PM
Last Post: AeglosGreeenleaf
  Hide button when clicked frequency 2 8,696 Dec-24-2018, 02:10 PM
Last Post: frequency
  [PyGUI] Hi All, how to hide/mask user input in PySimpleGUI nmrt 1 14,838 Sep-21-2018, 09:59 AM
Last Post: nmrt
  [PYQT5] Crashing when using .hide() and .show() aking76 0 7,269 Sep-18-2018, 02:09 PM
Last Post: aking76
  [Tkinter] How to show and hide tkinter entry box when select yes from drop down Prince_Bhatia 1 10,447 Jun-12-2018, 08:05 AM
Last Post: Larz60+
  [Tkinter] Hide text in entry box when i click on it. MeeranRizvi 1 11,050 Jan-25-2017, 10:38 AM
Last Post: MeeranRizvi
  Hide command window sparkz_alot 8 20,666 Sep-29-2016, 10:14 AM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020