Wednesday, November 27, 2024
Google search engine
HomeLanguageswxPython – GetFrame() function of wx.MenuBar

wxPython – GetFrame() function of wx.MenuBar

In this article we are going to learn about GetFrame() function associated with wx.MenuBar class of wxPython. GetFrame() function is used to get the parent frame of the menubar. And we can manipulate the frame.
No parameters are required in GetFrame() function

Syntax: wx.MenuBar.GetFrame(self)

Parameters: No parameters are required in GetFrame() function

Code Example #1:




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")
        self.item.SetBitmap(wx.Bitmap('right.png'))
  
        # SET BLUE COLOUR FOR TEXT FORMAT(R, B, G, A)
        self.item.SetTextColour((79, 81, 230, 255))
        self.fileMenu.Append(self.item)
        self.menubar.Append(self.fileMenu, '&File')
        self.SetMenuBar(self.menubar)
        self.SetSize((350, 250))
        self.SetTitle('Icons and shortcuts')
        self.Centre()
  
        # GET wx.Frame OBJECT
        frame = self.menubar.GetFrame()
  
        # PRINT TITLE OF frame
        print(frame.GetTitle())
def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
  
  
if __name__ == '__main__':
    main()


Output Window:

Console Output:

Icons and shortcuts

Code Example #2:




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")
        self.item.SetBitmap(wx.Bitmap('right.png'))
  
        # SET BLUE COLOUR FOR TEXT FORMAT(R, B, G, A)
        self.item.SetTextColour((79, 81, 230, 255))
        self.fileMenu.Append(self.item)
        self.menubar.Append(self.fileMenu, '&File')
        self.SetMenuBar(self.menubar)
        self.SetSize((350, 250))
  
        # GET wx.Frame OBJECT
        frame = self.menubar.GetFrame()
        # SET NEW TITLE FOR FRAME
        frame.SetTitle('New Frame Title')
        self.Centre()
  
def main():
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
  
  
if __name__ == '__main__':
    main()


Output:

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments