我正在使用wxPython来构建表单。我是wxpython的新手。我的第一个表单正确打开,当您按下Travel Advisory按钮时,第二个表单将打开。这是用户输入信息的地方。当我使用这行代码来输入文本时:
self.logger = wx.TextCtrl(self,pos =(100,145),size =(140,-1))
它会抹掉表格上的其他一切。评论该线路和表格是好的。我无法解决这个问题,似乎无法在网上找到一个好的答案。到目前为止,这是我的代码。任何帮助都会很棒。
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()
答案 0 :(得分:1)
在您的班级formTAN的#create表单部分
self.logger = wx.TextCtrl(self, pos=(100, 145), size=(140,-1))
是自我的父母,它需要为自己的孩子的小组育儿
self.logger = wx.TextCtrl(panel, pos=(100, 145), size=(140,-1))
班级#Txt的#Extra Details部分
self.logger = wx.TextCtrl(self, pos=(100, 170), size=(400, 150),
style=wx.TE_MULTILINE | wx.TE_READONLY)
也是自我的父亲,因此也需要为面板提供育儿,其高度150使其覆盖其他控件, 将高度更改为100可以将其排除。
self.logger = wx.TextCtrl(panel, pos=(100, 170), size=(400, 100),
style=wx.TE_MULTILINE | wx.TE_READONLY)