Hello
I am trying to write a GUI. I would like the contents of some BoxSizers to be
changed when the user clicks on certain buttons. In this example, clicking
the "Add" button should add several buttons to the self.typesizer.
When I click the button one of my new buttons a button appears in the top left
of the GUI (not where I had intended) but if I resize the frame, even
slightly then the buttons all jump to where I wanted them to go.
I've tried telling the frame to refresh and update but with no joy
Can anyone tell me where I'm going wrong?
Thanks a lot
Doc.
#!/usr/bin/python
import wx
class ChooseFoodType(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
topsizer = wx.BoxSizer(wx.VERTICAL)
titlelabel = "Create order"
title = wx.StaticText(self, -1, titlelabel)
topsizer.Add(title, 0, wx.ALIGN_CENTER_HORIZONTAL)
lefttorightsizer = wx.BoxSizer(wx.HORIZONTAL)
leftsizer = wx.BoxSizer(wx.VERTICAL)
typelabel = wx.StaticText(self, -1, "Type: ")
leftsizer.Add(typelabel, 0, wx.ALIGN_LEFT)
self.typesizer = wx.BoxSizer(wx.VERTICAL)
leftsizer.Add(self.typesizer, 1, wx.EXPAND)
sizelabel = wx.StaticText(self, -1, "Size: ")
leftsizer.Add(sizelabel, 0, wx.ALIGN_LEFT)
self.sizesizer = wx.BoxSizer(wx.VERTICAL)
leftsizer.Add(self.sizesizer, 1, wx.EXPAND)
exactlabel = wx.StaticText(self, -1, "Please Choose: ")
leftsizer.Add(exactlabel, 0, wx.ALIGN_LEFT)
self.exactsizer = wx.BoxSizer(wx.VERTICAL)
leftsizer.Add(self.exactsizer, 1, wx.EXPAND)
extraslabel = wx.StaticText(self, -1, "Extras: ")
leftsizer.Add(extraslabel, 0, wx.ALIGN_LEFT)
self.extrassizer = wx.BoxSizer(wx.VERTICAL)
leftsizer.Add(self.extrassizer, 1, wx.EXPAND)
lefttorightsizer.Add(leftsizer, 2, wx.EXPAND)
rightsizer = wx.BoxSizer(wx.VERTICAL)
receiptlabel = wx.StaticText(self, -1, "Receipt: ")
rightsizer.Add(receiptlabel, 0, wx.ALIGN_LEFT)
self.receiptlistbox = wx.ListBox(self)
rightsizer.Add(self.receiptlistbox, 1, wx.EXPAND)
receiptbuttonssizer = wx.BoxSizer(wx.HORIZONTAL)
addbutton = wx.Button(self, -1, "Add")
addbutton.Bind(wx.EVT_BUTTON, self.Add)
receiptbuttonssizer.Add(addbutton, 1, wx.EXPAND)
editbutton = wx.Button(self, -1, "Edit")
receiptbuttonssizer.Add(editbutton, 1, wx.EXPAND)
deletebutton = wx.Button(self, -1, "Remove")
receiptbuttonssizer.Add(deletebutton, 1, wx.EXPAND)
rightsizer.Add(receiptbuttonssizer, 0, wx.EXPAND)
lefttorightsizer.Add(rightsizer, 1, wx.EXPAND)
topsizer.Add(lefttorightsizer, 1, wx.EXPAND)
self.SetSizer(topsizer)
def Add(self, ID):
frame = ID.GetEventObject().GetGrandParent()
parent = ID.GetEventObject().GetParent()
typechildren = self.typesizer.GetChildren()
for a in typechildren:
a.Destroy()
typesizer = wx.BoxSizer(wx.HORIZONTAL)
pizzabutton = wx.Button(self, -1, "Pizza")
typesizer.Add(pizzabutton, 1, wx.EXPAND)
burgerbutton = wx.Button(self, -1, "Burger")
typesizer.Add(burgerbutton, 1, wx.EXPAND)
otherbutton = wx.Button(self, -1, "Other")
typesizer.Add(otherbutton, 1, wx.EXPAND)
self.typesizer.Add(typesizer, 1, wx.EXPAND)
frame.Refresh()
frame.Update()
app = wx.App()
frame = wx.Frame(None, -1, "My Frame")
frame.Show()
ChooseFoodType(frame)
app.MainLoop()