我正在尝试使用wxPython将垂直滚动条添加到我的某个笔记本标签中。我尝试将窗口样式wx.VSCROLL添加到几个不同的面板中,但我没有运气。这是我的代码:
import wx
import os
class MyFrame(wx.Frame):
def __init__(self, parent, ID, title):
wx.Frame.__init__(self, parent, ID, title=title, size=(500,200))
main = wx.Panel(self)
nb = wx.Notebook(main)
loginPg = wx.Panel(nb)
entryPg = wx.Panel(nb, style=wx.VSCROLL) //<--- This kind of works
projectsPg = wx.Panel(nb)
nb.AddPage(loginPg, "Login")
nb.AddPage(entryPg, "Entry")
nb.AddPage(projectsPg, "Projects")
self.entTitle = titlePanel(entryPg, -1)
self.entLabel = labelPanel(entryPg, -1)
self.entDescription = descrPanel(entryPg, -1)
mainSizer = wx.BoxSizer(wx.VERTICAL)
entryPgBox = wx.BoxSizer(wx.VERTICAL)
mainSizer.Add(nb, 1, wx.ALL|wx.EXPAND)
entryPgBox.Add(self.entTitle, 0, wx.EXPAND)
entryPgBox.Add(self.entLabel, 0, wx.EXPAND)
entryPgBox.Add(self.entDescription, 0, wx.EXPAND)
entryPg.SetAutoLayout(True)
entryPg.SetSizer(entryPgBox)
entryPgBox.Fit(entryPg)
main.SetAutoLayout(True)
main.SetSizer(mainSizer)
mainSizer.Fit(main)
self.Layout()
self.Show()
app = wx.App(False)
frame = MyFrame(None, -1, 'Test')
frame.Show()
app.MainLoop()
我的目标是让笔记本的第二个标签“Entry”可以垂直滚动。通过将style = wx.VSCROLL添加到entryPg,我获得了该选项卡的滚动条,但它不会向下滚动。如何让我的Notebook Tab entryPg有一个向下滚动的垂直滚动条? 非常感谢任何帮助!
答案 0 :(得分:1)
使用wx.ScrolledWindow
代替wx.Panel
来获取垂直滚动条。
这是一个最小的例子:
import wx
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.entry = wx.ScrolledWindow( self.notebook, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.HSCROLL|wx.VSCROLL )
self.entry.SetScrollRate( 5, 5 )
entry_sizer = wx.BoxSizer( wx.VERTICAL )
self.text = wx.StaticText( self.entry, wx.ID_ANY, u"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc, Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc,", wx.DefaultPosition, wx.DefaultSize, 0 )
self.text.Wrap( 600 )
entry_sizer.Add( self.text, 1, wx.ALL, 0 )
self.entry.SetSizer( entry_sizer )
self.entry.Layout()
entry_sizer.Fit( self.entry )
self.notebook.AddPage( self.entry, u"Entry", True )
sizer.Add( self.notebook, 1, wx.EXPAND |wx.ALL, 0 )
self.SetSizer( sizer )
self.Layout()
self.Centre( wx.BOTH )
self.Show()
if __name__ == "__main__":
app = wx.App()
Frame(None)
app.MainLoop()
此处Entry
页面将同时包含垂直和水平滚动条。请注意,仅当窗口小部件的内容溢出当前显示的大小时,滚动条才会处于活动状态。如果最大化此应用程序窗口,则sccrollbars将消失。