views:

106

answers:

1

I am trying to make a ScrolledWindow that can scroll over a grid of images, but the scrollbar isn't appearing. wxWidgets documentation says:

The most automatic and newest way [to set the scrollbars in wxScrolledWindow] is to simply let sizers determine the scrolling area. This is now the default when you set an interior sizer into a wxScrolledWindow with wxWindow::SetSizer. The scrolling area will be set to the size requested by the sizer and the scrollbars will be assigned for each orientation according to the need for them and the scrolling increment set by wxScrolledWindow::SetScrollRate

So I try to set the sizer of my ScrolledWindow with a GridSizer but it's not working. The code:

import wx

class MyFrame(wx.Frame):

    def __init__(self, parent, id=-1,title="",pos=wx.DefaultPosition,
         size=wx.DefaultSize, style=wx.DEFAULT_FRAME_STYLE,
         name="frame"):

        wx.Frame.__init__(self,parent,id,title,pos,size,style,name)

        self.panel = wx.ScrolledWindow(self,wx.ID_ANY)

        menuBar = wx.MenuBar()
        menu1 = wx.Menu()
        m = menu1.Append(wx.NewId(), "&Blah", "Show Pictures")
        menuBar.Append(menu1,"&Blah")
        self.Bind(wx.EVT_MENU,self.OnInit,m)

        self.SetMenuBar(menuBar)

    def OnInit(self, event):

        sizer = wx.GridSizer(rows=7,cols=3)

        filenames = []
        for i in range(20):
            filenames.append("img"+str(i)+".png")
        for fn in filenames:
            img = wx.Image(fn,wx.BITMAP_TYPE_ANY)
            sizer.Add(wx.StaticBitmap(self.panel,wx.ID_ANY,wx.BitmapFromImage(img)))

        self.panel.SetSizer(sizer)

class MyApp(wx.App):

    def OnInit(self):

        self.frame = MyFrame(parent=None,title="Frame")
        self.frame.Show()
        self.SetTopWindow(self.frame)
        return True

if __name__ == "__main__":

    app = MyApp()
    app.MainLoop()
A: 

Insert this

self.panel.SetScrollbars(1, 1, 1, 1)

after self.panel = wx.ScrolledWindow(self,wx.ID_ANY)

If you want some info on the SetScrollBars method then look at this wxwidgets documentation page

volting