簡體   English   中英

wxPython滾動面板滾動條大小調整問題

[英]wxPython scrolled panel scroll bar sizing issue

我正在構建一個我正在構建的GUI問題。 我的應用程序目前結構有兩個筆記本並排,下面有一個終端/日志textCtrl。 左側筆記本包含各種輸入和輸出面板,右側筆記本包含一個或多個matplotlib圖形。

問題是,在左側筆記本中,我有一個由3個垂直堆疊的面板組成的頁面。 前兩個有標准控件(checkboxes,textctrls和comboboxes)。 在這些“設置”下面是一個wx.grid.Grid,它包含用於在右邊的mpl圖中繪制的一些參數的I / O. 這個網格可以變得非常大,所以我把它放到一個滾動的面板中。 一切都在Windows中工作正常,但在Linux上我得到的是y_scroll欄比可見面板的高度高(這樣滾動條的下半部分沒有顯示) - 如果這是有道理的。

我把一個有類似問題的小代碼放在一起 - 滾動條與實際面板的高度不同。 我究竟做錯了什么?

import wx
import wx.grid as grd
import wx.lib.scrolledpanel as scrolled



# A sample panel with some check box controls to take up space, within a
# static box sizer
class SamplePanel(wx.Panel):
    def __init__(self,parent):
        wx.Panel.__init__(self,parent)

        grid = wx.GridBagSizer()
        for i in (0,1):
            grid.Add(wx.StaticText(self,label="Blah Blah: "),pos=(i,0))
            grid.Add(wx.CheckBox(self),pos=(i,1))

        box = wx.StaticBox(self, -1, "Some Settings: ")
        box_sizer = wx.StaticBoxSizer(box,wx.VERTICAL)
        box_sizer.Add(grid, 0, wx.ALL)
        self.SetSizer(box_sizer)
        self.Layout()


# A sample "table" of some parameters, let's say
class SampleGrid(grd.Grid):
    def __init__(self,parent):
        grd.Grid.__init__(self,parent)

        self.CreateGrid(20,4)
        self.SetColLabelValue(0,"Value")
        self.SetColLabelValue(1,"Lo-Bound")
        self.SetColLabelValue(2,"Hi-Bound")
        self.SetColLabelValue(3,"Fit")



# The main panel:        
class AnotherPanel(wx.Panel):
    def __init__(self, parent):
        wx.Panel.__init__(self,parent)

        # main sizer for everything:
        mainSizer = wx.BoxSizer(wx.VERTICAL)

        # Add a few "sample panels":
        mainSizer.Add(SamplePanel(self),0,wx.CENTER)
        mainSizer.Add(SamplePanel(self),0,wx.CENTER)
        mainSizer.Add(SamplePanel(self),0,wx.CENTER)

        # Create the grid which will be scrollable:
        scrolledPanel = scrolled.ScrolledPanel(self, size=(425,400))
        table = SampleGrid(scrolledPanel)
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(table,1,wx.ALL|wx.EXPAND,5)
        scrolledPanel.SetSizer(sizer)
        scrolledPanel.Layout()
        scrolledPanel.SetupScrolling(scroll_x=False)

        # Put the scrolled panel into a static box:
        box = wx.StaticBox(self,-1,"Parameters: ")
        sizer2 = wx.StaticBoxSizer(box,wx.VERTICAL)
        sizer2.Add(scrolledPanel,1,wx.EXPAND)

        mainSizer.Add(sizer2,1,wx.EXPAND)
        self.SetSizer(mainSizer)
        self.Fit()


# The main frame:
class MainFrame(wx.Frame):
    def __init__(self,parent,title):
        wx.Frame.__init__(self,parent,-1,title=title, size=(850,500))

        # Put 2 panels side by side:        
        sizer = wx.BoxSizer(wx.HORIZONTAL)
        sizer.Add(AnotherPanel(self),1,wx.EXPAND)
        sizer.Add(AnotherPanel(self),1,wx.EXPAND)

        self.SetSizer(sizer)
        self.SetAutoLayout(1)


# And, the app and mainloop:
app = wx.App(False)
frame = MainFrame(None, "Scroll Test")
frame.Show(True)
app.MainLoop()

在此先感謝您的幫助! 這也是我的第一個帖子,所以我提前為任何虛假的道歉 - 我試圖避免任何! ;)

在代碼中編輯一些拼寫錯誤,現在運行正常

在Windows和Linux上編輯2我有Python 2.7.3(Enthough Canopy發行版)和wxPython 2.8.10.1。

只需刪除scrolledPanel實例的硬編碼大小:

scrolledPanel = scrolled.ScrolledPanel(self)

這對我來說在CentOS上運行wxPython 2.8.12和Python 2.6.6

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM