拆分器窗口问题

时间:2014-07-15 08:19:18

标签: python wxpython

我将对话框拆分为2个部分,并使用grid sizer在第1部分中单独显示列表。我还使用list的长度来创建radiobox来保存三个按钮。但是使用以下脚本我无法显示滚动条以查看完整的项目列表。任何修复它的建议都会令人感激。

import wx
# I have following list available: lut_code

class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, "Modify Hydrologic Condition", wx.DefaultPosition, wx.Size(900, 600))

        splitter = wx.SplitterWindow(self, -1)
        scroll1 = wx.ScrolledWindow(splitter, -1)
        scroll1.SetBackgroundColour(wx.WHITE)
        scroll1.SetVirtualSize(scroll1.GetBestSize() + (250,250))
        scroll1.SetScrollRate(10,10)


        grid_sizer = wx.GridSizer( 0, 8, 0, 0 )

        self.head1 = wx.StaticText(scroll1, wx.ID_ANY, u"Code", (15,5))
        self.head1.Wrap( -1 )
        grid_sizer.Add( self.head1, 0, wx.ALL, 5 )

        v = 0
        for lu in lut_code:
            v += 40
            self.column11 = wx.StaticText(scroll1, wx.ID_ANY, str(lu), (15,v))
            self.column11.Wrap( -1 )
            grid_sizer.Add( self.column11, 0, wx.ALL, 5 )


        rb = 0
        radio1Choices = ['F','G','P']
        for i in range(1,len(lut_code)):
            rb += 40
            self.radio1 = wx.RadioBox(scroll1, wx.ID_ANY, wx.EmptyString, (550,rb), (30,5), radio1Choices, 3, wx.RA_SPECIFY_COLS | wx.NO_BORDER)
            self.radio1.SetSelection( 0 )
            grid_sizer.Add( self.radio1, 0, wx.ALL, 5)

        scroll2 = wx.ScrolledWindow(splitter,-1)
        scroll2.SetBackgroundColour("light-grey")
        message = """Blank"""

        wx.StaticText(scroll2, -1,message, (15,150))
        splitter.SplitVertically(scroll1,scroll2,-220)

    def OnClose(self, event):
        self.Show(False)

class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, -1, 'splitterwindow.py')
        frame.Show(True)
        self.SetTopWindow(frame)
        return True

app = MyApp(0)
app.MainLoop()

2 个答案:

答案 0 :(得分:1)

在添加项目后设置ScrolledWindow的SetVirtualSize,因此可以计算大小以包含它们。

答案 1 :(得分:1)

您需要在scroll2 =wx.ScrolledWindow(splitter,-1)

下面的程序中添加
scroll1.SetVirtualSize(scroll1.GetBestSize())

  import wx
# I have following list available: lut_code

class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, "Modify Hydrologic Condition", wx.DefaultPosition, wx.Size(900, 500))

        splitter = wx.SplitterWindow(self, -1)
        scroll1 = wx.ScrolledWindow(splitter, -1)
        scroll1.SetBackgroundColour(wx.WHITE)
        #scroll1.SetVirtualSize(scroll1.GetBestSize() + (250,250))
        scroll1.SetScrollRate(1,1)


        grid_sizer = wx.GridSizer( 0, 8, 0, 0 )

        self.head1 = wx.StaticText(scroll1, wx.ID_ANY, u"Code", (15,5))
        self.head1.Wrap( -1 )
        grid_sizer.Add( self.head1, 0, wx.ALL, 5 )

        v = 0

        lut_code=[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]
        for lu in lut_code:
            v += 40
            self.column11 = wx.StaticText(scroll1, wx.ID_ANY, str(lu), (15,v))
            self.column11.Wrap( -1 )
            grid_sizer.Add( self.column11, 0, wx.ALL, 5 )


        rb = 0
        radio1Choices = ['F','G','P']
        for i in range(0,len(lut_code)):
            rb += 40
            self.radio1 = wx.RadioBox(scroll1, wx.ID_ANY, wx.EmptyString, (550,rb), (30,5), radio1Choices, 3, wx.RA_SPECIFY_COLS | wx.NO_BORDER)
            self.radio1.SetSelection( 0 )
            grid_sizer.Add( self.radio1, 0, wx.ALL, 5)

        scroll2 =wx.ScrolledWindow(splitter,-1)
        scroll1.SetVirtualSize(scroll1.GetBestSize())# + (250,250))
        #wx.SetupScrolling(self, scroll_x=True, scroll_y=True, rate_x=20, rate_y=20, scrollToTop=True)


        scroll2.SetBackgroundColour("light-grey")
        message = """Blank"""

        wx.StaticText(scroll2, -1,message, (15,150))
        splitter.SplitVertically(scroll1,scroll2,-220)

    def OnClose(self, event):
        self.Show(False)

class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, -1, 'splitterwindow.py')
        frame.Show(True)
        self.SetTopWindow(frame)
        return True

app = MyApp(0)
app.MainLoop()

输出: enter image description here