Wxpython:在Windows和Linux中表现不同的代码

2024-04-19 18:05:58 发布

您现在位置:Python中文网/ 问答频道 /正文

下面的代码在windows和linux平台上都能很好地编译和运行,但是windows中缺少了需要滚动查看的字段(V\u scroll),但是linux没有这样的问题。wx 3.0安装在windows中,2.8.1安装在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()

Tags: selfaddallchangelabellistexpandwx
1条回答
网友
1楼 · 发布于 2024-04-19 18:05:58

我不明白你为什么要用这么多的尺寸,这里我用FlexGridSizer代替。但你的问题其实是因为你使用自整定器(vbox)然后稍后自整定器(sizer),第一个应该是自我滚动设置器(vbox)。你知道吗

下面有一个问题我还没有弄清楚,那就是我定义的TextCtrlwx.展开没有扩张。你知道吗

#!/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()

相关问题 更多 >