0

我想制作一个可以使用 wxnotebook 滚动到页面外区域的程序,因为我必须在显示器上使用的区域对于程序来说太小了。我尝试了一种方法,但无法让滚动工作。这是我所拥有的示例代码。我希望能够滚动,以便可以访问所有按钮。提前致谢。

import wx
import math as m
import  wx.lib.scrolledpanel as scrolled



class PageOne(scrolled.ScrolledPanel):


    def __init__(self, parent):
        scrolled.ScrolledPanel.__init__(self, parent,
                                        style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER)

        self.SetupScrolling()

        font = wx.Font(10, wx.ROMAN, wx.NORMAL, wx.NORMAL)


        self.name1= wx.TextCtrl(self, -1, '',  (10, 35), (70, -1))
        self.name2= wx.TextCtrl(self, -1, '',  (10, 35+30), (70, -1))
        self.name3= wx.TextCtrl(self, -1, '',  (10, 35+60), (70, -1))
        self.name4= wx.TextCtrl(self, -1, '',  (10, 35+90), (70, -1))
        self.name5= wx.TextCtrl(self, -1, '',  (10, 35+120), (70, -1))
        self.name6= wx.TextCtrl(self, -1, '',  (10, 35+150), (70, -1))
        self.name7= wx.TextCtrl(self, -1, '',  (10, 35+180), (70, -1))
        self.name8= wx.TextCtrl(self, -1, '',  (10, 35+210), (70, -1))
        self.name9= wx.TextCtrl(self, -1, '',  (10, 35+240), (70, -1))
        self.name10= wx.TextCtrl(self, -1, '',  (10, 35+270), (70, -1))
        self.name11= wx.TextCtrl(self, -1, '',  (10, 35+300), (70, -1))
        self.name12= wx.TextCtrl(self, -1, '',  (10, 35+330), (70, -1))
        self.name13= wx.TextCtrl(self, -1, '',  (10, 35+360), (70, -1))
        self.name14= wx.TextCtrl(self, -1, '',  (10, 35+390), (70, -1))
        self.name15= wx.TextCtrl(self, -1, '',  (10, 35+420), (70, -1))
        self.name16= wx.TextCtrl(self, -1, '',  (10, 35+450), (70, -1))
        self.name17= wx.TextCtrl(self, -1, '',  (10, 35+480), (70, -1))
        self.name18= wx.TextCtrl(self, -1, '',  (10, 35+510), (70, -1))


        self.to1= wx.TextCtrl(self, -1, '',  (90, 35), (40, -1))
        self.to2= wx.TextCtrl(self, -1, '',  (90, 35+30), (40, -1))
        self.to3= wx.TextCtrl(self, -1, '',  (90, 35+60), (40, -1))
        self.to4= wx.TextCtrl(self, -1, '',  (90, 35+90), (40, -1))
        self.to5= wx.TextCtrl(self, -1, '',  (90, 35+120), (40, -1))
        self.to6= wx.TextCtrl(self, -1, '',  (90, 35+150), (40, -1))
        self.to7= wx.TextCtrl(self, -1, '',  (90, 35+180), (40, -1))
        self.to8= wx.TextCtrl(self, -1, '',  (90, 35+210), (40, -1))
        self.to9= wx.TextCtrl(self, -1, '',  (90, 35+240), (40, -1))
        self.to10= wx.TextCtrl(self, -1, '',  (90, 35+270), (40, -1))
        self.to11= wx.TextCtrl(self, -1, '',  (90, 35+300), (40, -1))
        self.to12= wx.TextCtrl(self, -1, '',  (90, 35+330), (40, -1))
        self.to13= wx.TextCtrl(self, -1, '',  (90, 35+360), (40, -1))
        self.to14= wx.TextCtrl(self, -1, '',  (90, 35+390), (40, -1))
        self.to15= wx.TextCtrl(self, -1, '',  (90, 35+420), (40, -1))
        self.to16= wx.TextCtrl(self, -1, '',  (90, 35+450), (40, -1))
        self.to17= wx.TextCtrl(self, -1, '',  (90, 35+480), (40, -1))
        self.to18= wx.TextCtrl(self, -1, '',  (90, 35+510), (40, -1))


        self.topc1= wx.TextCtrl(self, -1, '',  (140, 35), (40, -1))
        self.topc2= wx.TextCtrl(self, -1, '',  (140, 35+30), (40, -1))
        self.topc3= wx.TextCtrl(self, -1, '',  (140, 35+60), (40, -1))
        self.topc4= wx.TextCtrl(self, -1, '',  (140, 35+90), (40, -1))
        self.topc5= wx.TextCtrl(self, -1, '',  (140, 35+120), (40, -1))
        self.topc6= wx.TextCtrl(self, -1, '',  (140, 35+150), (40, -1))
        self.topc7= wx.TextCtrl(self, -1, '',  (140, 35+180), (40, -1))
        self.topc8= wx.TextCtrl(self, -1, '',  (140, 35+210), (40, -1))
        self.topc9= wx.TextCtrl(self, -1, '',  (140, 35+240), (40, -1))
        self.topc10= wx.TextCtrl(self, -1, '',  (140, 35+270), (40, -1))
        self.topc11= wx.TextCtrl(self, -1, '',  (140, 35+300), (40, -1))
        self.topc12= wx.TextCtrl(self, -1, '',  (140, 35+330), (40, -1))
        self.topc13= wx.TextCtrl(self, -1, '',  (140, 35+360), (40, -1))
        self.topc14= wx.TextCtrl(self, -1, '',  (140, 35+390), (40, -1))
        self.topc15= wx.TextCtrl(self, -1, '',  (140, 35+420), (40, -1))
        self.topc16= wx.TextCtrl(self, -1, '',  (140, 35+450), (40, -1))
        self.topc17= wx.TextCtrl(self, -1, '',  (140, 35+480), (40, -1))
        self.topc18= wx.TextCtrl(self, -1, '',  (140, 35+510), (40, -1))


        panel = wx.Panel(self, -1, (195,35), (5,630),  style=wx.SUNKEN_BORDER)

        wx.ToggleButton(self, 1, '', (210, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+40, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+80, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+120, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+160, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+200, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+240, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+280, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+320, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+360, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+400, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+440, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+480, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+520, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+560, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+600, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+640, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+680, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+720, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+760, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+800, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+840, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+880, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+920, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+960, 35),(30,20))










class MainFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "Scroll",(1,1),(3000,800))

        # Here we create a panel and a notebook on the panel
        p = wx.Panel(self)
        nb = wx.Notebook(p)

        # create the page windows as children of the notebook
        page1 = PageOne(nb)


        # add the pages to the notebook with the label to show on the tab
        nb.AddPage(page1, "Page 1")


        # finally, put the notebook in a sizer for the panel to manage
        # the layout
        sizer = wx.BoxSizer()
        sizer.Add(nb, 1, 0)
        p.SetSizer(sizer)


if __name__ == "__main__":
    app = wx.App()
    MainFrame().Show()
    app.MainLoop()
4

1 回答 1

0

你很亲密。您实际上希望滚动面板作为顶部面板而不是笔记本中的页面。所以改为这样做:

import wx
import math as m
import  wx.lib.scrolledpanel as scrolled



class PageOne(wx.Panel):


    def __init__(self, parent):
        wx.Panel.__init__(self, parent)

        font = wx.Font(10, wx.ROMAN, wx.NORMAL, wx.NORMAL)


        self.name1= wx.TextCtrl(self, -1, '',  (10, 35), (70, -1))
        self.name2= wx.TextCtrl(self, -1, '',  (10, 35+30), (70, -1))
        self.name3= wx.TextCtrl(self, -1, '',  (10, 35+60), (70, -1))
        self.name4= wx.TextCtrl(self, -1, '',  (10, 35+90), (70, -1))
        self.name5= wx.TextCtrl(self, -1, '',  (10, 35+120), (70, -1))
        self.name6= wx.TextCtrl(self, -1, '',  (10, 35+150), (70, -1))
        self.name7= wx.TextCtrl(self, -1, '',  (10, 35+180), (70, -1))
        self.name8= wx.TextCtrl(self, -1, '',  (10, 35+210), (70, -1))
        self.name9= wx.TextCtrl(self, -1, '',  (10, 35+240), (70, -1))
        self.name10= wx.TextCtrl(self, -1, '',  (10, 35+270), (70, -1))
        self.name11= wx.TextCtrl(self, -1, '',  (10, 35+300), (70, -1))
        self.name12= wx.TextCtrl(self, -1, '',  (10, 35+330), (70, -1))
        self.name13= wx.TextCtrl(self, -1, '',  (10, 35+360), (70, -1))
        self.name14= wx.TextCtrl(self, -1, '',  (10, 35+390), (70, -1))
        self.name15= wx.TextCtrl(self, -1, '',  (10, 35+420), (70, -1))
        self.name16= wx.TextCtrl(self, -1, '',  (10, 35+450), (70, -1))
        self.name17= wx.TextCtrl(self, -1, '',  (10, 35+480), (70, -1))
        self.name18= wx.TextCtrl(self, -1, '',  (10, 35+510), (70, -1))


        self.to1= wx.TextCtrl(self, -1, '',  (90, 35), (40, -1))
        self.to2= wx.TextCtrl(self, -1, '',  (90, 35+30), (40, -1))
        self.to3= wx.TextCtrl(self, -1, '',  (90, 35+60), (40, -1))
        self.to4= wx.TextCtrl(self, -1, '',  (90, 35+90), (40, -1))
        self.to5= wx.TextCtrl(self, -1, '',  (90, 35+120), (40, -1))
        self.to6= wx.TextCtrl(self, -1, '',  (90, 35+150), (40, -1))
        self.to7= wx.TextCtrl(self, -1, '',  (90, 35+180), (40, -1))
        self.to8= wx.TextCtrl(self, -1, '',  (90, 35+210), (40, -1))
        self.to9= wx.TextCtrl(self, -1, '',  (90, 35+240), (40, -1))
        self.to10= wx.TextCtrl(self, -1, '',  (90, 35+270), (40, -1))
        self.to11= wx.TextCtrl(self, -1, '',  (90, 35+300), (40, -1))
        self.to12= wx.TextCtrl(self, -1, '',  (90, 35+330), (40, -1))
        self.to13= wx.TextCtrl(self, -1, '',  (90, 35+360), (40, -1))
        self.to14= wx.TextCtrl(self, -1, '',  (90, 35+390), (40, -1))
        self.to15= wx.TextCtrl(self, -1, '',  (90, 35+420), (40, -1))
        self.to16= wx.TextCtrl(self, -1, '',  (90, 35+450), (40, -1))
        self.to17= wx.TextCtrl(self, -1, '',  (90, 35+480), (40, -1))
        self.to18= wx.TextCtrl(self, -1, '',  (90, 35+510), (40, -1))


        self.topc1= wx.TextCtrl(self, -1, '',  (140, 35), (40, -1))
        self.topc2= wx.TextCtrl(self, -1, '',  (140, 35+30), (40, -1))
        self.topc3= wx.TextCtrl(self, -1, '',  (140, 35+60), (40, -1))
        self.topc4= wx.TextCtrl(self, -1, '',  (140, 35+90), (40, -1))
        self.topc5= wx.TextCtrl(self, -1, '',  (140, 35+120), (40, -1))
        self.topc6= wx.TextCtrl(self, -1, '',  (140, 35+150), (40, -1))
        self.topc7= wx.TextCtrl(self, -1, '',  (140, 35+180), (40, -1))
        self.topc8= wx.TextCtrl(self, -1, '',  (140, 35+210), (40, -1))
        self.topc9= wx.TextCtrl(self, -1, '',  (140, 35+240), (40, -1))
        self.topc10= wx.TextCtrl(self, -1, '',  (140, 35+270), (40, -1))
        self.topc11= wx.TextCtrl(self, -1, '',  (140, 35+300), (40, -1))
        self.topc12= wx.TextCtrl(self, -1, '',  (140, 35+330), (40, -1))
        self.topc13= wx.TextCtrl(self, -1, '',  (140, 35+360), (40, -1))
        self.topc14= wx.TextCtrl(self, -1, '',  (140, 35+390), (40, -1))
        self.topc15= wx.TextCtrl(self, -1, '',  (140, 35+420), (40, -1))
        self.topc16= wx.TextCtrl(self, -1, '',  (140, 35+450), (40, -1))
        self.topc17= wx.TextCtrl(self, -1, '',  (140, 35+480), (40, -1))
        self.topc18= wx.TextCtrl(self, -1, '',  (140, 35+510), (40, -1))


        panel = wx.Panel(self, -1, (195,35), (5,630),  style=wx.SUNKEN_BORDER)

        wx.ToggleButton(self, 1, '', (210, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+40, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+80, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+120, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+160, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+200, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+240, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+280, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+320, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+360, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+400, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+440, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+480, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+520, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+560, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+600, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+640, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+680, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+720, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+760, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+800, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+840, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+880, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+920, 35),(30,20))
        wx.ToggleButton(self, 1, '', (210+960, 35),(30,20))

class MainFrame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "Scroll",(1,1),(600,600))

        # Here we create a panel and a notebook on the panel
        s = scrolled.ScrolledPanel(self, style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER)
        s.SetupScrolling()
        nb = wx.Notebook(s)

        # create the page windows as children of the notebook
        page1 = PageOne(nb)


        # add the pages to the notebook with the label to show on the tab
        nb.AddPage(page1, "Page 1")


        # finally, put the notebook in a sizer for the panel to manage
        # the layout
        sizer = wx.BoxSizer()
        sizer.Add(nb, 1, 0)
        s.SetSizer(sizer)


if __name__ == "__main__":
    app = wx.App()
    MainFrame().Show()
    app.MainLoop()
于 2013-08-02T13:38:23.693 回答