Friday, September 5, 2025
HomeLanguageswxPython – SetMargins() function in wx.ToolBar

wxPython – SetMargins() function in wx.ToolBar

In this article we are going to learn about SetMargins() function associated with wx.ToolBar class of wxPython. SetMargins() function set the values to be used as margins for the toolbar. It takes two integer x and y as parameter for left and right margins.

Syntax:

wx.ToolBar.SetMargins(self, x, y)

Parameters:

Parameter Input Type Description
x int Left margin, right margin and inter-tool separation value.
y int Top margin, bottom margin and inter-tool separation value.

Return Type:

wx.ToolBarToolBase

Code Example 1: 

Python3




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.toolbar = self.CreateToolBar()
        self.toolbar.SetMargins(20, 10)
        td = self.toolbar.AddTool(1, 'right', wx.Bitmap('right.png'))
        self.toolbar.Realize()
        print(self.toolbar.GetMargins())
        self.SetSize((350, 250))
        self.SetTitle('Undo redo')
        self.Centre()
 
    def OnQuit(self, e):
 
        self.Close()
 
 
def main():
 
    app = wx.App()
    ex = Example(None)
    ex.Show()
    app.MainLoop()
 
 
if __name__ == '__main__':
    main()


Output:

(20, 10)
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6634 POSTS0 COMMENTS
Nicole Veronica
11801 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11863 POSTS0 COMMENTS
Shaida Kate Naidoo
6750 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6701 POSTS0 COMMENTS
Umr Jansen
6718 POSTS0 COMMENTS