2014-09-22 6 views
0

我正在使用wxPython來建立窗體。我是wxpython的新手。我的第一張表格正確打開,當您按下旅行顧問按鈕時,第二張表格打開。這是用戶輸入信息的地方。當我使用這行代碼可以輸入文本:
self.logger = wx.TextCtrl(self,pos =(100,145),size =(140,-1)) 它會抹去所有其他內容表格。註釋行,表單很好。我很難解決這個問題,似乎無法在網上找到一個好的答案。這是我的代碼到目前爲止。任何幫助都會很棒。使用wxPython的wx.TextCtrl塊的其餘形式

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() 

回答

1

在#創建類的組成部分formTAN

self.logger = wx.TextCtrl(self, pos=(100, 145), size=(140,-1)) 

被父自我,它需要養育到自

self.logger = wx.TextCtrl(panel, pos=(100, 145), size=(140,-1)) 

的#的子面板額外的細節部分你的班級形式譚

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) 
+0

謝謝你,它完美的作品。我明白我的錯誤。 – 2014-09-22 17:27:46