2015-09-02 25 views
0

以下代碼在Windows和Linux平臺上編譯並運行良好,但需要滾動查看的字段(V_scroll)從窗口中缺失,但linux沒有這樣的問題。 wx 3.0安裝在windows和2.8.1在linux中。這會是一個問題嗎?Wxpython:在Windows和Linux中表現不同的代碼

#!/usr/bin/python 
# -*- coding: utf-8 -*- 
import wx 
import wx.lib.filebrowsebutton as filebrowse 
class Frame (wx.Frame): 
    def __init__(self, parent): 
     wx.Frame.__init__ (self, parent, id = wx.ID_ANY, title = u"Test", pos = wx.DefaultPosition, size = wx.Size(600,300), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL) 

     self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize) 
     sizer = wx.BoxSizer(wx.VERTICAL) 

     self.notebook = wx.Notebook(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0) 
     self.login = wx.Panel(self.notebook, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL) 
     self.notebook.AddPage(self.login, u"Login", False) 
     self.scroll = wx.ScrolledWindow(self.notebook, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.HSCROLL|wx.VSCROLL) 
     vbox = wx.BoxSizer(wx.VERTICAL) 

     # Sizer for widgets inside tabs 
     inside_sizer_h1 = wx.BoxSizer(wx.HORIZONTAL) 
     inside_sizer_h2 = wx.BoxSizer(wx.HORIZONTAL) 
     inside_sizer_h3 = wx.BoxSizer(wx.HORIZONTAL) 
     inside_sizer_h4 = wx.BoxSizer(wx.HORIZONTAL) 
     inside_sizer_h5 = wx.BoxSizer(wx.HORIZONTAL) 
     inside_sizer_h6 = wx.BoxSizer(wx.HORIZONTAL) 
     inside_sizer_h7 = wx.BoxSizer(wx.HORIZONTAL) 
     inside_sizer_h8 = wx.BoxSizer(wx.HORIZONTAL) 
     inside_sizer_h9 = wx.BoxSizer(wx.HORIZONTAL) 

     #Test Approve Label 
     self.test_app_label = wx.StaticText(self.scroll, -1 , label="Test Approved By :") 
     inside_sizer_h1.Add(self.test_app_label, 1, wx.ALL,5) 

     #Test Approve Combo 
     self.tes_app_combo = wx.ComboBox(self.scroll, -1, value='None', choices= ['None', 'approver1', 'approver2', 'approver3', 'approver4']) 
     inside_sizer_h1.Add(self.tes_app_combo, 1, wx.ALL, 5) 


     #Workspace Label 
     self.wrksp_label = wx.StaticText(self.scroll, -1 , label="Workspace :") 
     inside_sizer_h2.Add(self.wrksp_label, 1, wx.ALL,5) 

     #Workspace file selector 
     self.select_wrksp_dir = filebrowse.DirBrowseButton(self.scroll, -1,labelText = "", toolTip = 'Select tip of your workspace') 
     inside_sizer_h2.Add(self.select_wrksp_dir, 1, wx.ALL|wx.EXPAND, 5) 

     # Issuelist label 
     self.ar_list_label = wx.StaticText(self.scroll, -1 , label="Issue List :") 
     inside_sizer_h3.Add(self.ar_list_label, 1, wx.ALL,5) 

     # Issue Text box 
     self.ar_list_text = wx.TextCtrl(self.scroll, -1, value=u"Enter The issue, one per line", style=wx.TE_MULTILINE) 
     inside_sizer_h3.Add(self.ar_list_text, 1, wx.ALL, 5) 

     # Summary of change Title 
     self.change_summary_label = wx.StaticText(self.scroll, -1 , label=u"Summary of change :") 
     inside_sizer_h4.Add(self.change_summary_label, 1, wx.ALL, 5) 

     # Summary of change Text Box 
     self.change_summary_text = wx.TextCtrl(self.scroll, -1, value=u"What componet has changed?",style=wx.TE_MULTILINE) 
     inside_sizer_h4.Add(self.change_summary_text, 1, wx.ALL, 5) 

     # Changed File List Title 
     self.change_file_list_label = wx.StaticText(self.scroll, -1 , label=u"Changed File List :") 
     inside_sizer_h5.Add(self.change_file_list_label,1, wx.ALL, 5) 

     # Changed File List Box 
     self.change_summary_text = wx.TextCtrl(self.scroll, -1, u' enter list of changed files',style=wx.TE_MULTILINE) 
     inside_sizer_h5.Add(self.change_summary_text,1, wx.ALL, 5) 

     # GUI Testing done label 
     self.testing_done_label = wx.StaticText(self.scroll, -1 , label=u"What tests have you done? :") 
     inside_sizer_h6.Add(self.testing_done_label,1, wx.ALL, 5) 

     #FlexGUi Checkbox 
     self.gui_check_list = wx.CheckListBox(self.scroll, -1, choices=['GUI Builds Successfully', 'GUI Automation Tests', 'CLI Automation Tests']) 
     inside_sizer_h6.Add(self.gui_check_list,1, wx.ALL, 5) 

     # GUI Automation test logs label 
     self.gui_auto_log_label = wx.StaticText(self.scroll, -1 , label=u"Enter the logs :") 
     inside_sizer_h7.Add(self.gui_auto_log_label,1, wx.ALL, 5) 

     #GUI Automation test box 
     self.gui_auto_log = wx.TextCtrl(self.scroll, -1, u'Copy and paste the logs.',style=wx.TE_MULTILINE) 
     inside_sizer_h7.Add(self.gui_auto_log,1, wx.ALL, 5) 

     # Review URL Text 
     self.review_url_label = wx.StaticText(self.scroll, -1 , label=u"Code review URL :") 
     inside_sizer_h8.Add(self.review_url_label,1, wx.ALL, 5) 

     #Code Review Textbox 
     self.review_url_tbox = wx.TextCtrl(self.scroll, -1, value=u"Enter the code review URL",style=wx.TE_MULTILINE) 
     inside_sizer_h8.Add(self.review_url_tbox,1, wx.ALL, 5) 

     #Submit button 
     self.sub_button = wx.Button(self.scroll, label = 'Submit') 
     inside_sizer_h9.Add(self.sub_button,1, wx.ALL, 5) 

     #Cancel button 
     self.canc_button = wx.Button(self.scroll, label = 'Cancel') 
     inside_sizer_h9.Add(self.canc_button,1, wx.ALL, 5) 


     vbox.Add(inside_sizer_h1, 0 , wx.TOP|wx.EXPAND, 40) 
     vbox.Add(inside_sizer_h2, 0 , wx.ALL|wx.EXPAND, 5) 
     vbox.Add(inside_sizer_h3, 0 , wx.ALL|wx.EXPAND, 5) 
     vbox.Add(inside_sizer_h4, 0 , wx.ALL|wx.EXPAND, 10) 
     vbox.Add(inside_sizer_h5, 0 , wx.ALL|wx.EXPAND, 10) 
     vbox.Add(inside_sizer_h6, 0 , wx.ALL|wx.EXPAND, 10) 
     vbox.Add(inside_sizer_h7, 0 , wx.ALL|wx.EXPAND, 10) 
     vbox.Add(inside_sizer_h8, 0 , wx.ALL|wx.EXPAND, 10) 
     vbox.Add(inside_sizer_h9, 0 , wx.ALL|wx.EXPAND, 10) 

     self.Maximize() 
     self.scroll.Size = self.GetSize() 
     print self.GetSize() 
     self.scroll.SetScrollbars(20,25,45,50) 
     self.SetSizer(vbox) 
     self.SetSizerAndFit(vbox) 
     self.Layout() 

     self.notebook.AddPage(self.scroll, u"Delivery", True) 

     sizer.Add(self.notebook, 1, wx.EXPAND |wx.ALIGN_RIGHT|wx.ALL, 0) 

     self.SetSizer(sizer) 
     self.Layout() 

     self.Centre(wx.BOTH) 
     self.Show() 

if __name__ == "__main__": 
    app = wx.App() 
    Frame(None) 
    app.MainLoop() 
+0

在Windows上使用2.8.12.1我可以看到兩個按鈕,並且佈局退出了很多,然後如果我使用3.0.2或wxPython Phoenix。 Sizer的行爲在3.x中有所改變,但不確定這是否解釋了這個問題。 – Werner

+0

當使用WIT(http://wiki.wxpython.org/Widget%20Inspection%20Tool)時,我也沒有看到任何'內部'sizer,我還不明白爲什麼會發生這種情況。 – Werner

回答

0

我不明白你爲什麼使用這麼多sizer,在這裏我使用FlexGridSizer代替。但你的問題是由於你使用self.SetSizer(vbox),然後self.SetSizer(sizer),第一個應該是self.scroll.SetSizer(vbox)。

有一個問題我沒有想到與以下,這是我定義wx.EXPAND的TextCtrl沒有擴大。

#!/usr/bin/python 
# -*- coding: utf-8 -*- 
import wx 
print(wx.VERSION_STRING) 
import wx.lib.filebrowsebutton as filebrowse 


class Frame (wx.Frame): 
    def __init__(self, parent): 
     wx.Frame.__init__ (self, parent, id = wx.ID_ANY, title = u"Test", pos = wx.DefaultPosition, style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL) 

     sizer = wx.BoxSizer(wx.VERTICAL) 

     self.notebook = wx.Notebook(self, wx.ID_ANY) 
     self.login = wx.Panel(self.notebook, wx.ID_ANY) 
     self.notebook.AddPage(self.login, u"Login", False) 
     self.scroll = wx.lib.scrolledpanel.ScrolledPanel(self.notebook, wx.ID_ANY) 
     vbox = wx.BoxSizer(wx.VERTICAL) 

     # Sizer for widgets inside tabs 
     inside_sizer = wx.FlexGridSizer(cols=2) 
     button_sizer = wx.BoxSizer() 

     #Test Approve Label 
     self.test_app_label = wx.StaticText(self.scroll, -1 , label="Test Approved By :") 
     inside_sizer.Add(self.test_app_label, 1, wx.ALL,5) 

     #Test Approve Combo 
     self.tes_app_combo = wx.ComboBox(self.scroll, -1, value='None', choices= ['None', 'approver1', 'approver2', 'approver3', 'approver4']) 
     inside_sizer.Add(self.tes_app_combo, 1, wx.ALL, 5) 

     #Workspace Label 
     self.wrksp_label = wx.StaticText(self.scroll, -1 , label="Workspace :") 
     inside_sizer.Add(self.wrksp_label, 1, wx.ALL,5) 

     #Workspace file selector 
     self.select_wrksp_dir = filebrowse.DirBrowseButton(self.scroll, -1,labelText = "", toolTip = 'Select tip of your workspace') 
     inside_sizer.Add(self.select_wrksp_dir, 1, wx.ALL|wx.EXPAND, 5) 

     # Issuelist label 
     self.ar_list_label = wx.StaticText(self.scroll, -1 , label="Issue List :") 
     inside_sizer.Add(self.ar_list_label, 1, wx.ALL,5) 

     # Issue Text box 
     self.ar_list_text = wx.TextCtrl(self.scroll, -1, value=u"Enter The issue, one per line", style=wx.TE_MULTILINE) 
     inside_sizer.Add(self.ar_list_text, 1, wx.ALL|wx.EXPAND, 5) 

     # Summary of change Title 
     self.change_summary_label = wx.StaticText(self.scroll, -1 , label=u"Summary of change :") 
     inside_sizer.Add(self.change_summary_label, 1, wx.ALL, 5) 

     # Summary of change Text Box 
     self.change_summary_text = wx.TextCtrl(self.scroll, -1, value=u"What componet has changed?",style=wx.TE_MULTILINE) 
     inside_sizer.Add(self.change_summary_text, 1, wx.ALL|wx.EXPAND, 5) 

     # Changed File List Title 
     self.change_file_list_label = wx.StaticText(self.scroll, -1 , label=u"Changed File List :") 
     inside_sizer.Add(self.change_file_list_label,1, wx.ALL, 5) 

     # Changed File List Box 
     self.change_summary_text = wx.TextCtrl(self.scroll, -1, u' enter list of changed files',style=wx.TE_MULTILINE) 
     inside_sizer.Add(self.change_summary_text,1, wx.ALL|wx.EXPAND, 5) 

     # GUI Testing done label 
     self.testing_done_label = wx.StaticText(self.scroll, -1 , label=u"What tests have you done? :") 
     inside_sizer.Add(self.testing_done_label,1, wx.ALL, 5) 

     #FlexGUi Checkbox 
     self.gui_check_list = wx.CheckListBox(self.scroll, -1, choices=['GUI Builds Successfully', 'GUI Automation Tests', 'CLI Automation Tests']) 
     inside_sizer.Add(self.gui_check_list,1, wx.ALL, 5) 

     # GUI Automation test logs label 
     self.gui_auto_log_label = wx.StaticText(self.scroll, -1 , label=u"Enter the logs :") 
     inside_sizer.Add(self.gui_auto_log_label,1, wx.ALL, 5) 

     #GUI Automation test box 
     self.gui_auto_log = wx.TextCtrl(self.scroll, -1, u'Copy and paste the logs.',style=wx.TE_MULTILINE) 
     inside_sizer.Add(self.gui_auto_log,1, wx.ALL|wx.EXPAND, 5) 

     # Review URL Text 
     self.review_url_label = wx.StaticText(self.scroll, -1 , label=u"Code review URL :") 
     inside_sizer.Add(self.review_url_label,1, wx.ALL, 5) 

     #Code Review Textbox 
     self.review_url_tbox = wx.TextCtrl(self.scroll, -1, value=u"Enter the code review URL",style=wx.TE_MULTILINE) 
     inside_sizer.Add(self.review_url_tbox,1, wx.ALL|wx.EXPAND, 5) 

     #Submit button 
     self.sub_button = wx.Button(self.scroll, label = 'Submit') 
     button_sizer.Add(self.sub_button,1, wx.ALL, 5) 

     #Cancel button 
     self.canc_button = wx.Button(self.scroll, label = 'Cancel') 
     button_sizer.Add(self.canc_button,1, wx.ALL, 5) 

     vbox.Add(inside_sizer, 1, wx.TOP|wx.EXPAND, 40) 
     vbox.Add(button_sizer, 1, wx.TOP, 40) 

     self.scroll.SetupScrolling() 
     self.scroll.SetSizer(vbox) 

     self.notebook.AddPage(self.scroll, u"Delivery", True) 

     sizer.Add(self.notebook, 1, wx.EXPAND|wx.ALIGN_RIGHT|wx.ALL, 0) 

     self.SetSizer(sizer) 
     self.Layout() 

     self.Centre(wx.BOTH) 
     self.Show() 
     self.Maximize() 

if __name__ == "__main__": 
    import wx.lib.mixins.inspection as WIT 
    app = WIT.InspectableApp() 
    Frame(None) 
    app.MainLoop() 
相關問題