I have a little app that I am working on with wxPython.
I have a scrolled window using wx.ScrolledWindow
. It seems to refuse to repaint the contents when it is scrolled.
Example:
Code that created above example:
import wx
class SaveEdFrame(wx.Frame):
def __init__(self, *args, **kwds):
kwds["style"] = wx.DEFAULT_FRAME_STYLE|wx.EXPAND
wx.Frame.__init__(self, *args, **kwds)
self.__do_layout()
self.Bind(wx.EVT_SIZE, self.onSize)
def __mainSizer(self):
self.mainSizer = wx.BoxSizer(wx.VERTICAL)
for key in xrange(30):
self.headerLabel = wx.StaticText(self, -1, "TestStr %s" % key)
self.mainSizer.Add(self.headerLabel)
return self.mainSizer
def __do_layout(self):
## begin wxGlade: SaveEdFrame.__do_layout
self.scroll = wx.ScrolledWindow(self, style=wx.FULL_REPAINT_ON_RESIZE)
self.scroll.SetScrollbars(1, 10, 1, 10)
self.scroll.SetSizer(self.__mainSizer())
def onSize(self, event):
self.scroll.SetSize(self.GetClientSize())
self.Refresh()
if __name__ == "__main__":
app = wx.App(0)
mainFrame = SaveEdFrame(None)
app.SetTopWindow(mainFrame)
mainFrame.Show(True)
app.MainLoop()
I've been digging through the wxDocs, and it seems to me that one solution would be to subclass wx.ScrolledWindow
, manually catch wx.EVT_SCROLLWIN
events, and then explicitly redraw the window, but my attempts to do that failed when calling self.Refresh()
did not cause the interior of the wx.ScrolledWindow
to repaint.
Anyways, it seems to me that the whole point of the wx.ScrolledWindow
object is that it should handle repainting itself when scrolled.
What am I doing wrong?
Platform is W7-x64, python 2.7 32 bit, wxPython 2.8.11.0
I think the problem there is that your wx.StaticText widgets are children of the SaveEdFrame, not the ScrolledWindow. The ScrolledWindow is being redrawn over them as you scroll it. Try:
headerLabel = wx.StaticText(self.scroll, -1, "TestStr %s" % key)
self.mainSizer.Add(headerLabel)