Friday, October 10, 2025
HomeLanguageswxPython – SetMargins() with wx.Size parameters

wxPython – SetMargins() with wx.Size parameters

In this article we are going to learn about SetMargins() function associated with wx.ToolBar class of wxPython. Similarly with previous article SetMargins() function set the margins for the toolbar. But the only difference is rather taking two different parameters x and y it takes using wx.Size parameter.

Syntax:

wx.ToolBar.SetMargins(self, size)

Parameters:

Parameter Input Type Description
size wx.Size Margin Size.

Return Type: wx.ToolBarToolBase

Code Example: 

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()
        # set margins with size parameter
        self.toolbar.SetMargins(size =(30, 25))
        td = self.toolbar.AddTool(1, 'right', wx.Bitmap('right.png'))
        self.toolbar.Realize()
        # print margins
        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:

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

Most Popular

Dominic
32349 POSTS0 COMMENTS
Milvus
87 POSTS0 COMMENTS
Nango Kala
6717 POSTS0 COMMENTS
Nicole Veronica
11880 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11941 POSTS0 COMMENTS
Shaida Kate Naidoo
6838 POSTS0 COMMENTS
Ted Musemwa
7097 POSTS0 COMMENTS
Thapelo Manthata
6792 POSTS0 COMMENTS
Umr Jansen
6792 POSTS0 COMMENTS