Hello,
I'm new to wxPython and I'm struggling with wx.BoxSizer. The problem
is that all my widgets expand to take up the entire space available
and it looks horrible. For example:
myHSizer.Add(wx.Button(self, wx.ID_ANY, "Clear"),1,wx.EXPAND)
Here the "Clear" button expands, making the button a lot bigger than
the word "Clear". So the button looks wrong, and all the widgets are
touching each other. I have this problem with all widgets. I really
prefer the way things look on Gtk. Gtk is simple to use and the
widgets look right by default. Why can't WX do that?
Anyways, after struggling to find something about this on the
documentation I found about wx.ALL and wx.CENTER. I tried using those.
wx.ALL at improves things a little because at least the widgets are
not touching anymore, but I think it is totally the wrong way to look
at the problem. I don't want to put "x" pixels around the button. I
want the button to be a reasonable size based on its contents and have
the toolkit figure out how to space it properly.
Any ideas?
For completeness, I include demo source code of the application I want
to write:
···
####
# Daniel's dictionary application.
#
import wx
class MainWindow(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(300,200))
self.CreateStatusBar()
self.mySetContents()
self.mySetMenuBar()
self.Show(True)
#
# Main contents
#
def mySetContents(self):
# Boxes.
topHbox = wx.BoxSizer(wx.HORIZONTAL)
rightCol = wx.BoxSizer(wx.VERTICAL)
searchTerm = wx.BoxSizer(wx.HORIZONTAL)
# Radio buttons.
radioList = ['English -> German', 'German -> English']
radioBox = wx.RadioBox(self, wx.ID_ANY, "", wx.DefaultPosition,
wx.DefaultSize, radioList, 2, wx.RA_SPECIFY_ROWS)
#
# Search entry.
#
searchTerm.Add(wx.TextCtrl(self, wx.ID_ANY),2,wx.ALL|wx.CENTER,5)
searchTerm.Add(wx.Button(self, wx.ID_ANY, "Clear"),1,wx.ALL|
wx.CENTER,5)
#
# Search entry and output.
#
rightCol.Add(searchTerm,1,wx.EXPAND)
rightCol.Add(wx.StaticText(self, wx.ID_ANY, 'Foo'),4,wx.ALL|
wx.CENTER,5)
#
# Everything.
#
topHbox.Add(radioBox,1,wx.EXPAND)
topHbox.Add(rightCol,2,wx.EXPAND)
# Finish.
self.SetSizer(topHbox)
self.SetAutoLayout(1)
topHbox.Fit(self)
#
# Menu Bar
#
def mySetMenuBar(self):
# Setup menus.
fileMenu = wx.Menu()
fileMenu.Append(wx.ID_ANY, "E&xit","Terminate program.")
helpMenu = wx.Menu()
helpMenu.Append(wx.ID_ANY, "&Contents", "Open manual")
helpMenu.AppendSeparator()
helpMenu.Append(wx.ID_ANY, "&About", "Information about this
program.")
# Create menu bar.
menuBar = wx.MenuBar()
menuBar.Append(fileMenu, "&File")
menuBar.Append(helpMenu, "&Help")
# Menus done.
self.SetMenuBar(menuBar)
app = wx.PySimpleApp()
frame = MainWindow(None, wx.ID_ANY, "My Dictionary")
app.MainLoop()