Reputation: 139
I am using wxPython to build forms. I am new to wxpython. My first form opens correctly and when you press the Travel Advisory button the second form opens. This is where the users will enter information. When I use this line of code to be able to enter text:
self.logger = wx.TextCtrl(self, pos=(100, 145), size=(140,-1))
it will obliterate everything else on the form. Comment the line out and the form is good. I am having trouble figuring this out and cannot seem to find a good answer on the web. Here is my code so far. Any help would be great.
import wx
# varialbes
title = 'Advisory Form'
closuretypeList = ['is closed ', 'is open', 'closed for season ', 'open for season ']
stateList = ['Alabama','Alaska']
analystList = []
dotPhoneList = []
dotWebList = []
class formMS(wx.Frame):
#formMS is main switchboard
def __init__(self, parent, title):
# create form
super(formMS, self).__init__(parent,title=title,size=(225, 350))
panel = wx.Panel(self, -1)
font1 = wx.Font(11, wx.SWISS, wx.NORMAL, wx.BOLD, True)
#add static labels
text1 = wx.StaticText(panel, -1, "FORMS", (55, 15))
text1.SetFont(font1)
text2 = wx.StaticText(panel, -1, "REPORTS", (55, 110))
text2.SetFont(font1)
#Form buttons
self.buttonTAForm = wx.Button(panel,id=wx.ID_OPEN, label="Travel Advisory", pos = (55, 40))
self.buttonTAForm.Bind(wx.EVT_BUTTON, self.OnClick, self.buttonTAForm)
self.buttonDOTForm = wx.Button(panel,id=wx.ID_ANY, label="DOT Contacts", pos = (55, 75))
#Report Buttons
self.buttonTARep = wx.Button(panel,id=wx.ID_ANY, label="TA Report", pos = (55, 140))
self.buttonDOTContactRep = wx.Button(panel,id=wx.ID_ANY, label="DOT Contacts", pos = (55, 175))
#cancel button
self.buttonCancel = wx.Button(panel,id=wx.ID_CANCEL, label="Close",pos = (55,225))
self.buttonCancel.Bind(wx.EVT_BUTTON, self.OnCloseMe)
self.buttonCancel.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
self.Centre()
self.Show()
def OnClick(self, event):
secondWindow = formTAN(self)
secondWindow.Show()
def OnCloseMe(self, event):
self.Close(True)
def OnCloseWindow(self, event):
self.Close(True)
class formTAN(wx.Frame):
#formTAN is Travel Advisory Notice Form
def __init__(self, parent):
# create form
super(formTAN, self).__init__(parent,size=(550, 650))
panel = wx.Panel(self, -1)
font1 = wx.Font(11, wx.SWISS, wx.NORMAL, wx.BOLD, True)
font2 = wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD, False)
self.logger = wx.TextCtrl(self, pos=(100, 145), size=(140,-1))
#Label Panel
self.lblname = wx.StaticText(panel, -1, "TRAVEL ADVISORY FORM", (170, 15))
self.lblname.SetFont(font1)
#Clears form to create a new record
self.buttonNew = wx.Button(panel,id=wx.ID_ANY, label="New Record", pos = (55, 40))
#Exits Form
self.buttonCancel = wx.Button(panel,id=wx.ID_CANCEL, label="All Clear/Exit",pos = (380,40))
self.buttonCancel.Bind(wx.EVT_BUTTON, self.OnCloseMe)
#Selects type of closure
self.lblname = wx.StaticText(panel, -1, "Closure Type", (10, 85))
self.lblname.SetFont(font2)
self.choClosureType = wx.Choice(panel,-1, (100, 85),choices=closuretypeList)
# self.choClosureType.Bind(wx.EVT_CHOICE, self.OnSelect)
#Drop down list of states/provinces
self.lblname = wx.StaticText(panel, -1, "State", (10, 115))
self.lblname.SetFont(font2)
self.choStateType = wx.Choice(panel,-1, (100, 115),choices=stateList)
# self.choClosureType.Bind(wx.EVT_CHOICE, self.OnSelect)
#Enter strip map number
self.lblname = wx.StaticText(panel, -1, "Strip #:", (250, 115))
self.lblname.SetFont(font2)
# self.editname = wx.TextCtrl(self, value="", pos=(100, 145), size=(140, -1))
# self.Bind(wx.EVT_TEXT, self.EvtText, self.editname)
# self.Bind(wx.EVT_CHAR, self.EvtChar, self.editname)
#Enter route name
self.lblname = wx.StaticText(panel, -1, "Road Name:", (10, 145))
self.lblname.SetFont(font2)
#Enter area in question
self.lblname = wx.StaticText(panel, -1, "To / From:", (250, 145))
self.lblname.SetFont(font2)
#Extra Details
self.lblname = wx.StaticText(panel, -1, "Description:", (10, 175))
self.lblname.SetFont(font2)
# self.logger = wx.TextCtrl(self, pos=(100, 170), size=(400, 150), style=wx.TE_MULTILINE | wx.TE_READONLY)
#Dot Phone number
self.lblname = wx.StaticText(panel, -1, "DOT Phone:", (10, 275))
self.lblname.SetFont(font2)
self.choDotPhoneType = wx.Choice(panel,-1, (100, 275),choices=dotPhoneList)
#DOT websites
self.lblname = wx.StaticText(panel, -1, "DOT Website:", (250, 275))
self.lblname.SetFont(font2)
self.choDotWebType = wx.Choice(panel,-1, (350, 275),choices=dotWebList)
#Analyst list
self.lblname = wx.StaticText(panel, -1, "Analyst:", (10, 305))
self.lblname.SetFont(font2)
self.choAnalystType = wx.Choice(panel,-1, (100, 305),choices=analystList)
def OnCloseMe(self, event):
self.Close(True)
self.Centre()
self.Show()
if __name__ == '__main__':
app = wx.App()
formMS(None, title='Travel Advisory')
app.MainLoop()
Upvotes: 0
Views: 239
Reputation: 3625
In the # create form part of your class formTAN
self.logger = wx.TextCtrl(self, pos=(100, 145), size=(140,-1))
is parented to self, it needs parenting to the panel that is a child of self
self.logger = wx.TextCtrl(panel, pos=(100, 145), size=(140,-1))
The #Extra Details part of your class formTAN
self.logger = wx.TextCtrl(self, pos=(100, 170), size=(400, 150),
style=wx.TE_MULTILINE | wx.TE_READONLY)
is also parented to self so also needs parenting to panel, and its height 150 is making it cover other controls, changing the height to 100 sorts this out.
self.logger = wx.TextCtrl(panel, pos=(100, 170), size=(400, 100),
style=wx.TE_MULTILINE | wx.TE_READONLY)
Upvotes: 1