Hello!
I have a frame with some sizers in it (see code at th end for a running example). I would like to know how to repeat the sizers 2, 3 and 4 when pressing the add button. The sizers should be added before the submit button, and the control objects should have a different name because they have to be send to a MySQL database. Can anyone help?
Cheers!
Dani
import wx, MySQLdb, wx.lib.intctrl, time, datetime, wx.grid
from wx.lib import masked
class SpeciesSightDlg(wx.Dialog):
def __init__(self):
EnglishSpeciesHeader = wx.Font(20, wx.DEFAULT, wx.NORMAL, wx.BOLD, False, u'Times New Roman')
ScientificSpeciesHeader = wx.Font(20, wx.DEFAULT, wx.ITALIC, wx.BOLD, False, u'Times New Roman')
EnglishName = 'Great Tit'
ScientificName = 'Parus major'
wx.Dialog.__init__(self, None, -1,title = 'Enter species data', size=(700,650))
panel = wx.Panel(self, -1)
vbox = wx.BoxSizer(wx.VERTICAL)
#Define sizers
#Horizontal sizers
hbox1 = wx.BoxSizer(wx.HORIZONTAL)
hbox2 = wx.BoxSizer(wx.HORIZONTAL)
hbox3 = wx.BoxSizer(wx.HORIZONTAL)
hbox4 = wx.BoxSizer(wx.HORIZONTAL)
hbox5 = wx.BoxSizer(wx.HORIZONTAL)
ScientificName = wx.StaticText(panel, -1, ScientificName)
ScientificName.SetFont(ScientificSpeciesHeader)
EnglishName = wx.StaticText(panel, -1, EnglishName)
EnglishName.SetFont(EnglishSpeciesHeader)
CountKindTXT = wx.StaticText(panel, -1, 'Kind of count',size=(150, -1))
CountKindCombo1 = wx.ComboBox(panel, -1,size=(150, -1), choices=['Not counted','Exact count','At least','Approximation'], style = wx.CB_READONLY, value = 'Not counted')
IndividualsTXT = wx.StaticText(panel, -1, 'Number',size=(70, -1))
Individuals1 = masked.NumCtrl(panel, integerWidth=5, allowNegative=False,size=(70, -1))
AgeTXT = wx.StaticText(panel, -1, 'Age',size=(125, -1))
AgeCombo1 = wx.ComboBox(panel, -1,size=(125, -1), choices=['Adult','Nesting','Juvenile', 'Unmature','1st year','2nd year','3rd year','4th year','5th year', 'Unknown'], style = wx.CB_READONLY, value = 'Unknown')
SexTXT = wx.StaticText(panel, -1, 'Sex',size=(100, -1))
SexCombo1 = wx.ComboBox(panel, -1,size=(100, -1), choices=['Male', 'Female', 'Unknown'], style = wx.CB_READONLY, value = 'Unknown')
addBtn1 = wx.Button(panel, -1, 'Add', size = (50,-1))
Notes1 = wx.TextCtrl(panel, -1,size=(500, 75), style=wx.TE_MULTILINE, value = '')
submitBtn = wx.Button(panel, -1, 'Submit')
#Merge sizers
hbox1.Add(EnglishName, 0, wx.ALL, 5)
hbox1.Add(ScientificName, 0, wx.ALL, 5)
hbox2.Add(CountKindTXT, 0, wx.ALL, 5)
hbox2.Add(IndividualsTXT, 0, wx.ALL, 5)
hbox2.Add(AgeTXT, 0, wx.ALL, 5)
hbox2.Add(SexTXT, 0, wx.ALL, 5)
hbox3.Add(CountKindCombo1, 0, wx.ALL, 5)
hbox3.Add(Individuals1, 0, wx.ALL, 5)
hbox3.Add(AgeCombo1, 0, wx.ALL, 5)
hbox3.Add(SexCombo1, 0, wx.ALL, 5)
hbox3.Add(addBtn1, 0, wx.ALL, 5)
hbox4.Add(Notes1, 0, wx.ALL, 5)
hbox5.Add(submitBtn, 0, wx.ALL, 5)
vbox.Add(hbox1, 0, wx.ALIGN_LEFT | wx.ALL, 5)
vbox.Add(hbox2, 0, wx.ALIGN_LEFT | wx.ALL, 5)
vbox.Add(hbox3, 0, wx.ALIGN_LEFT | wx.ALL, 5)
vbox.Add(hbox4, 0, wx.ALIGN_LEFT | wx.ALL, 5)
vbox.Add(hbox5, 0, wx.ALIGN_RIGHT | wx.ALL, 5)
panel.SetSizer(vbox)
self.Centre()
self.Show(True)
app = wx.App()
SpeciesSightDlg()
app.MainLoop()