在 wxPython 中创建 ScrolledWindow [英] Creating ScrolledWindow in wxPython

查看:25
本文介绍了在 wxPython 中创建 ScrolledWindow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试制作一个可以在图像网格上滚动的 ScrolledWindow,但没有出现滚动条.wxWidgets 文档说:

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

[在wxScrolledWindow 中设置滚动条] 最自动和最新的方法是简单地让sizer 确定滚动区域.当您使用 wxWindow::SetSizer 将内部尺寸设置为 wxScrolledWindow 时,这是现在的默认设置.滚动区域将设置为 sizer 请求的大小,滚动条将根据需要为每个方向分配,以及由 wxScrolledWindow::SetScrollRate 设置的滚动增量

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

所以我尝试使用 GridSizer 设置我的 ScrolledWindow 的 sizer,但它不起作用.代码:

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()

推荐答案

插入此内容

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

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

如果您想了解有关 SetScrollBars 方法的信息,请查看此 wxwidgets 文档 页面

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

这篇关于在 wxPython 中创建 ScrolledWindow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆