滚动条消失/刷新不工作wx.python公司

用户

在下面的示例中,虽然layout函数被调用,但使用计算按钮后滚动条将消失。如果手动调整框架的大小,它会重新出现。这种行为只在windows下发生,在linux中滚动条正常工作。在

为了解决这个问题,我尝试了函数refresh()和update()(在类GUI图的布局函数中),但是没有用。在

我试图将我的应用程序简化为一个最小的工作示例:

# -*- coding: utf-8 -*-

import wx
from wx.lib.pubsub import pub
import wx.lib.scrolledpanel as scrolled
import matplotlib
matplotlib.use('WXAgg')
from matplotlib.figure import Figure
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigCanvas

class MainWindow(wx.Frame):
    '''Frame that contains pretty much everything'''
    def __init__(self,*args,**kwargs):
        '''Constructor'''
        super(MainWindow,self).__init__(*args,**kwargs)
        self.panel = wx.Panel(self)
        notebook = Notebook(self.panel)
        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(notebook,1, wx.ALL|wx.EXPAND,4)
        self.panel.SetSizerAndFit(sizer)
        self.panel.Layout()

class Notebook(wx.Notebook):
    def __init__(self, parent):
        wx.Notebook.__init__(self, parent, id=wx.ID_ANY, style = wx.BK_DEFAULT)
        tabTwo = GUI_Input_GHL(self) 
        self.AddPage(tabTwo, 'Input')
        tabThree = GUI_Diagrams_GHL(self)  
        self.AddPage(tabThree, 'Diagrams')

class GUI_Input_GHL(scrolled.ScrolledPanel):
    """This panel contains the input fields for basic data."""
    def __init__(self, parent):
        scrolled.ScrolledPanel.__init__(self, parent=parent, id=wx.ID_ANY)
        self.label_1 = wx.StaticText(self,-1,label=u'Label 1')
        self.button2 = wx.Button(self,-1,label=u'Start')
        self.Bind(wx.EVT_BUTTON, self.StartCalc, self.button2)
        self.layout()       

    def layout(self):    
        sizer = wx.GridBagSizer()
        sizer.Add(self.button2, (8,0),(2,3), flag =wx.EXPAND)
        sizer.Add(self.label_1, (0,0),flag=wx.ALIGN_CENTER_VERTICAL)
        self.SetAutoLayout(1)
        self.SetupScrolling()
        self.SetSizerAndFit(sizer)

    def StartCalc(self,event):
        pub.sendMessage('GUI_Diagrams_Listener', message = 'test')

class GUI_Diagrams_GHL(scrolled.ScrolledPanel):
    """This panel contains diagrams"""
    def __init__(self, parent):
        scrolled.ScrolledPanel.__init__(self, parent=parent, id=wx.ID_ANY)
        self.parent = parent
        self.fig1 = Figure()
        self.fig6 = Figure()
        self.canvas1 = FigCanvas(self,-1,self.fig1)
        self.axes1 = self.fig1.add_subplot(111)
        self.canvas6 = FigCanvas(self,-1,self.fig6)
        self.axes6 = self.fig6.add_subplot(111)
        self.dia_R_hat_SetValues('test')
        self.dia_theta_SetValues('test')
        self.layout()
        pub.subscribe(self.diagrams_SetValues, "GUI_Diagrams_Listener")


    def layout(self):
        sizer = wx.GridBagSizer()
        sizer.Add(self.canvas1,   (1,0), (12,12), wx.EXPAND)
        sizer.Add(self.canvas6,  (53,0), (12,12), wx.EXPAND)

        ## I guess here is the problem somewhere:
        self.SetSizerAndFit(sizer)
        self.SetAutoLayout(1)
        self.SetupScrolling()
        #self.Fit()
        #self.Layout()
        #self.FitInside()
        #self.AlwaysShowScrollbars(True,True)
        #self.Refresh()
        #self.Update()
        #self.parent.SetSize(self.parent.GetSize())

    def diagrams_SetValues(self, message):
        self.Output = message
        self.dia_R_hat_SetValues(message)
        self.dia_theta_SetValues(message)
        self.layout()

    def dia_R_hat_SetValues(self, Output):
        self.axes1.clear()
        self.axes1.plot(range(15),range(15), 'r-', linewidth = 2)
        self.canvas1.draw()

    def dia_theta_SetValues(self, Output):
        self.axes6.clear()
        self.axes6.plot(range(5),'k')
        self.axes6.set_title(r"Absolute Temperature")
        self.canvas6.draw()


if __name__ == '__main__':
    app = wx.App()
    frame = MainWindow(None, -1, 'MyApp')
    frame.Show()
    app.MainLoop()


已被浏览了5055次
更新日期: 2020-10-28 18:38:21
1 个回答
fefe Tyson

我自己想出来了:)

如果调用主面板的布局函数('MainWindow.panel.Layout()')更新diagram类布局中的diagrams/之后,整个面板将刷新并 滚动条重新出现。所以a'parent.parent.Layout()“在这个案子中为我工作。在

还有其他建议/解决方案吗?在

评论 - 2020年9月11日 20:34

最新Python问答

推荐Python问答