DevC
DevC

Reputation: 7423

wxpython toolbar textctrl spacing

I have textctrl in wxPython toolbar, I couldn't figure out how to align it with icons(22x22) and have some spacing/padding between toolbar icons and text control and also to frame borders.

import wx

class MyGUI(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(500, 500))

        menubar = wx.MenuBar()
        file = wx.Menu()
        help = wx.Menu()
        file.Append(101, '&Open', 'Open a new document')
        file.Append(102, '&Save', 'Save the document')
        file.AppendSeparator()
        quit = wx.MenuItem(file, 105, '&Quit\tCtrl+Q', 'Quit the Application')
        quit.SetBitmap(wx.Image('media/22/actions/system-log-out.png', wx.BITMAP_TYPE_PNG).ConvertToBitmap())
        file.AppendItem(quit)

        menubar.Append(file, '&File')
        menubar.Append(help, '&Help')
        self.SetMenuBar(menubar)
        self.CreateStatusBar()
        self.toolbar = self.CreateToolBar()

        textctrl = self.toolbar.AddControl( wx.TextCtrl( self.toolbar, wx.ID_ANY,size=(100, -1)))
        tconn = self.toolbar.AddLabelTool(wx.ID_UNDO, '', wx.Bitmap('media/22/actions/server-connect-icon.png'))
        tplay = self.toolbar.AddLabelTool(wx.ID_REDO, '', wx.Bitmap('media/22/actions/media-playback-start.png'))

        self.toolbar.AddSeparator()
        texit = self.toolbar.AddLabelTool(wx.ID_EXIT, '', wx.Bitmap('media/22/actions/stop.png'))
        self.toolbar.EnableTool(wx.ID_EXIT, False)
        self.toolbar.Realize()

class MyApp(wx.App):
    def OnInit(self):
        frame = MyGUI(None, -1, 'MyGUI')
        frame.SetBackgroundColour('#004681')
        frame.SetIcon(wx.Icon('media/launch.ico', wx.BITMAP_TYPE_ICO))
        frame.Show(True)
        return True


if __name__ == '__main__':
    app = MyApp(0)
    app.MainLoop()

Upvotes: 0

Views: 1433

Answers (1)

Mike Driscoll
Mike Driscoll

Reputation: 33071

The toolbar widget follows the look-and-feel of the OS's native toolbar, so there's really no way to change that. See the following thread:

In it there are a couple of workarounds using blank images or labels for spacing. Alternatively, you could just create your own toolbar with a horizontal box sizer and add all the widgets to it. Then you'll be able to use the sizer to space things out a bit.

Upvotes: 2

Related Questions