笔记本中的 wxPython scrolledwindow 不滚动
wxPython scrolledwindow in a notebook does not scroll
我想在笔记本的标签上滚动 windows。如果 window 太小,内容应该是可滚动的。如果 window 足够大,一切都会正确布局。当 window 太小无法容纳所有内容时,它看起来也正确,但滚动条永远不会出现,我也不能用鼠标滚轮滚动。这是我最少的失败案例:
#!/usr/bin/env python3
import wx
class MainWindow(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__ (self, parent, id = wx.ID_ANY, title = u"Title", pos = wx.DefaultPosition, size = wx.Size(800,480), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL)
self.SetSizeHints(wx.DefaultSize, wx.DefaultSize)
notebook = wx.Notebook(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0)
for tab in range(0,3):
scrolled_window = wx.ScrolledWindow(notebook, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.HSCROLL|wx.VSCROLL)
sizer = wx.GridSizer(0, 5, 0, 0)
scrolled_window.SetScrollRate(5, 5)
scrolled_window.SetSizer(sizer)
notebook.AddPage(scrolled_window, "Tab %d" % tab, False)
scrolled_window.SetScrollbars(1, 1, 1, 1)
for btn in range(0,50):
button = wx.Button(scrolled_window, wx.ID_ANY, str(btn), wx.DefaultPosition, wx.DefaultSize, 0)
button.SetMinSize((-1, 90))
sizer.Add(button, 0, wx.ALL|wx.EXPAND, 5)
sizer.Fit(scrolled_window)
self.Layout()
app = wx.App(False)
main_window = MainWindow(parent=None)
main_window.Show(True)
app.MainLoop()
此外,我看到此断言失败(每个选项卡一次或每当我更改选项卡时):
(scroll_bug.py:8990): Gtk-CRITICAL **: 09:02:58.514: gtk_box_gadget_distribute: assertion 'size >= 0' failed in GtkNotebook
感谢帮助
我不确定,但问题可能在于尝试在笔记本中使用 ScrolledWindow
作为从属子项 window。
面板更合适。
尝试使用 ScrolledPanel
代替,例如
#!/usr/bin/env python3
import wx
import wx.lib.scrolledpanel as scrolled
class MainWindow(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__ (self, parent, id = wx.ID_ANY, title = u"Title", pos = wx.DefaultPosition, size = wx.Size(800,480), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL)
self.SetSizeHints(wx.DefaultSize, wx.DefaultSize)
self.panel = wx.Panel(self)
notebook = wx.Notebook(self.panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0)
for tab in range(0,3):
scrolled_window = scrolled.ScrolledPanel(notebook, wx.ID_ANY)
scrolled_window.SetupScrolling()
notebook.AddPage(scrolled_window, "Tab %d" % tab, False)
bsizer = wx.GridSizer(0, 5, 0, 0)
for btn in range(0,50):
button = wx.Button(scrolled_window, wx.ID_ANY, str(btn), wx.DefaultPosition, wx.DefaultSize, 0)
button.SetMinSize((-1, 90))
bsizer.Add(button, 0, wx.ALL|wx.EXPAND, 5)
scrolled_window.SetSizer(bsizer)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(notebook, 1, wx.ALL| wx.EXPAND, 5)
self.panel.SetSizer(sizer)
self.Layout()
self.Refresh()
app = wx.App(False)
main_window = MainWindow(parent=None)
main_window.Show(True)
app.MainLoop()
我想在笔记本的标签上滚动 windows。如果 window 太小,内容应该是可滚动的。如果 window 足够大,一切都会正确布局。当 window 太小无法容纳所有内容时,它看起来也正确,但滚动条永远不会出现,我也不能用鼠标滚轮滚动。这是我最少的失败案例:
#!/usr/bin/env python3
import wx
class MainWindow(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__ (self, parent, id = wx.ID_ANY, title = u"Title", pos = wx.DefaultPosition, size = wx.Size(800,480), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL)
self.SetSizeHints(wx.DefaultSize, wx.DefaultSize)
notebook = wx.Notebook(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0)
for tab in range(0,3):
scrolled_window = wx.ScrolledWindow(notebook, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.HSCROLL|wx.VSCROLL)
sizer = wx.GridSizer(0, 5, 0, 0)
scrolled_window.SetScrollRate(5, 5)
scrolled_window.SetSizer(sizer)
notebook.AddPage(scrolled_window, "Tab %d" % tab, False)
scrolled_window.SetScrollbars(1, 1, 1, 1)
for btn in range(0,50):
button = wx.Button(scrolled_window, wx.ID_ANY, str(btn), wx.DefaultPosition, wx.DefaultSize, 0)
button.SetMinSize((-1, 90))
sizer.Add(button, 0, wx.ALL|wx.EXPAND, 5)
sizer.Fit(scrolled_window)
self.Layout()
app = wx.App(False)
main_window = MainWindow(parent=None)
main_window.Show(True)
app.MainLoop()
此外,我看到此断言失败(每个选项卡一次或每当我更改选项卡时):
(scroll_bug.py:8990): Gtk-CRITICAL **: 09:02:58.514: gtk_box_gadget_distribute: assertion 'size >= 0' failed in GtkNotebook
感谢帮助
我不确定,但问题可能在于尝试在笔记本中使用 ScrolledWindow
作为从属子项 window。
面板更合适。
尝试使用 ScrolledPanel
代替,例如
#!/usr/bin/env python3
import wx
import wx.lib.scrolledpanel as scrolled
class MainWindow(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__ (self, parent, id = wx.ID_ANY, title = u"Title", pos = wx.DefaultPosition, size = wx.Size(800,480), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL)
self.SetSizeHints(wx.DefaultSize, wx.DefaultSize)
self.panel = wx.Panel(self)
notebook = wx.Notebook(self.panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0)
for tab in range(0,3):
scrolled_window = scrolled.ScrolledPanel(notebook, wx.ID_ANY)
scrolled_window.SetupScrolling()
notebook.AddPage(scrolled_window, "Tab %d" % tab, False)
bsizer = wx.GridSizer(0, 5, 0, 0)
for btn in range(0,50):
button = wx.Button(scrolled_window, wx.ID_ANY, str(btn), wx.DefaultPosition, wx.DefaultSize, 0)
button.SetMinSize((-1, 90))
bsizer.Add(button, 0, wx.ALL|wx.EXPAND, 5)
scrolled_window.SetSizer(bsizer)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(notebook, 1, wx.ALL| wx.EXPAND, 5)
self.panel.SetSizer(sizer)
self.Layout()
self.Refresh()
app = wx.App(False)
main_window = MainWindow(parent=None)
main_window.Show(True)
app.MainLoop()