wxpython多个面板_在wxpython中滚动多个面板时出现问题

您将每个面板作为滚动小部件的子部件。但您将每个面板添加到sizer,然后错误地将框架的sizer设置为名为“sizer”的sizer。在

这是一个不匹配,几乎总是有坏的视觉效果。在

你应该选一个滚动的.setzer(尺寸)

或者创建一个新的sizer,比如称之为framesizer,然后将scrolled添加到其中。那么自调整器(framesizer)where self if the josh()帧。在

另外,除非子窗口小部件比滚动面板大,否则滚动面板不会显示它的滚动条。在# Broken down here to show sizer child-parent hiearchy

# AND widget child-parent hiearchy need to be congruent

import wx

import wx.lib.scrolledpanel

scrolled = wx.lib.scrolledpanel #i use reload(...) in pyslices.py

class Panel(wx.Panel):

def __init__(self, parent, color='black'):

wx.Panel.__init__(self, parent, size=(800,100))

# several "Panels" sized added together

# are bigger than ScrolledPanel size

self.SetMinSize( (800, 100) )

self.SetBackgroundColour( color )

widget1 = wx.TextCtrl(self, style=wx.TE_MULTILINE)

widget2 = wx.TextCtrl(self, style=wx.TE_MULTILINE)

sizer = wx.BoxSizer(wx.VERTICAL)

sizer.Add( widget1, 1, wx.ALL | wx.EXPAND, 15 )

sizer.Add( widget2, 1, wx.ALL | wx.EXPAND, 15 )

self.SetSizer( sizer )

class BigPanel(wx.Panel):

def __init__(self, parent):

# at least one child widget or aggregate width

# of several child widgets has to be wider than

# ScrolledPanel to show its horizontal scroll bar

# at least one child widget or aggregate height

# of more then one child widget has to be "taller" than

# the height of the ScrolledPanel for it to show

# its vertical scroll bar

# -V -V

wx.Panel.__init__(self, parent, size=(800,800))

# -^ -^

panel0 = Panel(self, 'black')

panel1 = Panel(self, 'red')

panel2 = Panel(self, 'green')

panel3 = Panel(self, 'blue')

panel4 = Panel(self, 'white')

panel5 = Panel(self, 'purple')

sizer = wx.BoxSizer(wx.VERTICAL)

sizer.Add( panel0, 1, wx.ALL | wx.EXPAND, 15 )

sizer.Add( panel1, 1, wx.ALL | wx.EXPAND, 15 )

sizer.Add( panel2, 1, wx.ALL | wx.EXPAND, 15 )

sizer.Add( panel3, 1, wx.ALL | wx.EXPAND, 15 )

sizer.Add( panel4, 1, wx.ALL | wx.EXPAND, 15 )

sizer.Add( panel5, 1, wx.ALL | wx.EXPAND, 15 )

self.SetSizer( sizer )

class ScrolledPanel(scrolled.ScrolledPanel):

def __init__(self, parent):

# -V -V

scrolled.ScrolledPanel.__init__(self, parent, size=(400,400))

# -^ -^

bigpanel = BigPanel(self)

sizer = wx.BoxSizer(wx.VERTICAL)

sizer.Add( bigpanel, 1, wx.ALL | wx.EXPAND, 15 )

self.SetSizer( sizer )

self.SetAutoLayout(1)

self.SetupScrolling()

class Frame(wx.Frame):

def __init__(self):

wx.Frame.__init__(self, parent = wx.GetApp().GetTopWindow(),

title = 'Trouble with scrolling through several panels in wxpython',

size = (500,400))

scroll = ScrolledPanel(self)

sizer = wx.BoxSizer(wx.VERTICAL)

sizer.Add( scroll, 1, wx.ALL | wx.EXPAND, 15 )

self.SetSizer( sizer )

if __name__ == '__main__':

app = wx.GetApp()

if not app: app = wx.App(0)

frame = Frame()

frame.Show()

if not app.IsMainLoopRunning():

app.MainLoop()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值