wxPython控制項學習之wx.lib.scrolledpanel.ScrolledPanel

來源:互聯網
上載者:User

 

1. ScrolledPanel類,wx.ScrolledWindow的子類之一。提供了自動捲軸和滾動行為。此外也提供了wx.ScrolledWindow不具有的標籤遍曆管理功能(tab traversal management)

2. 方法集

 SetupScrolling(self, scroll_x, scroll_y, rate_x, rate_y, scrollToTop)該方法需要顯示調用,綁定必須的的事件去完成適合的滾動

 

# -*- coding: UTF-8 -*-#-------------------------------------------------------------------------------# Name:        模組1# Purpose:## Author:      ankier## Created:     10/11/2012# Copyright:   (c) ankier 2012# Licence:     <your licence>#-------------------------------------------------------------------------------import wximport  wx.lib.scrolledpanel as scrolledclass ScrolledPanelFrame(wx.Frame):    def __init__(self):        wx.Frame.__init__(self, None, -1, 'Combo Box Example')                        mainFlexSizer = wx.FlexGridSizer(2,1,25,-1)        panel = scrolled.ScrolledPanel(self, -1)                headLabel = wx.StaticText(self, -1, "Head label, you will always see it")                panelFlexSizer = wx.FlexGridSizer(3,4,6,6)                staticText1 = wx.StaticText(panel, -1, "First name:")        textBox1 = wx.wx.TextCtrl(panel, -1, size =(210, 50))                staticText2 = wx.StaticText(panel, -1, "Second name:")        textBox2 = wx.wx.TextCtrl(panel, -1, size =(210, 50))        staticText3 = wx.StaticText(panel, -1, "Last name:")        textBox3 = wx.wx.TextCtrl(panel, -1, size =(210, 50))        staticText4 = wx.StaticText(panel, -1, "Sex:")        textBox4 = wx.wx.TextCtrl(panel, -1, size =(210, 50))                staticText5 = wx.StaticText(panel, -1, "First name:")        textBox5 = wx.wx.TextCtrl(panel, -1, size =(210, 50))                staticText6 = wx.StaticText(panel, -1, "Second name:")        textBox6 = wx.wx.TextCtrl(panel, -1, size =(210, 50))        panelFlexSizer.AddMany([                                (staticText1, 0, wx.SHAPED|wx.ALIGN_LEFT),(textBox1, 0, wx.SHAPED)                                ,(staticText2, 0, wx.SHAPED|wx.ALIGN_LEFT),(textBox2, 0, wx.SHAPED)                                ,(staticText3, 0, wx.SHAPED|wx.ALIGN_LEFT),(textBox3, 0, wx.SHAPED)                                ,(staticText4, 0, wx.SHAPED|wx.ALIGN_LEFT),(textBox4, 0, wx.SHAPED)                                ,(staticText5, 0, wx.SHAPED|wx.ALIGN_LEFT),(textBox5, 0, wx.SHAPED)                                ,(staticText6, 0, wx.SHAPED|wx.ALIGN_LEFT),(textBox6, 0, wx.SHAPED)                                ])        panelFlexSizer.AddGrowableCol(1)        panelFlexSizer.AddGrowableCol(3)                panel.SetSizerAndFit(panelFlexSizer)        panel.SetAutoLayout(1)        panel.SetupScrolling()                                mainFlexSizer.AddMany([                               (headLabel, 0, wx.SHAPED|wx.ALIGN_LEFT),                                 (panel, 1, wx.EXPAND)                               ])        mainFlexSizer.AddGrowableCol(0)        mainFlexSizer.AddGrowableRow(1)                        self.SetSizerAndFit(mainFlexSizer)                #由於Frame的MinSize的計算是有其sizer所包括的控制項所佔的空間,所決定的。        #所以如果我們想繼續拖動Frame以改變其大小,我們需要重新計算和修正改Frame的MinSize,                self.SetMinSize((300,200))               def main():    app = wx.PySimpleApp()    ScrolledPanelFrame().Show()    app.MainLoop()if __name__ == '__main__':    main()

 

import wx import wx.lib.scrolledpanel as scrolled  ######################################################################## class MyForm(wx.Frame):          #----------------------------------------------------------------------         def __init__(self):                 wx.Frame.__init__(self, None, wx.ID_ANY, "Tutorial", size=(200,500))                  # Add a panel so it looks the correct on all platforms                 self.panel = wx.Panel(self, wx.ID_ANY)                  # --------------------                 # Scrolled panel stuff                 self.scrolled_panel = scrolled.ScrolledPanel(self.panel, -1,  style = wx.TAB_TRAVERSAL|wx.SUNKEN_BORDER, name="panel1")                 self.scrolled_panel.SetAutoLayout(1)                 self.scrolled_panel.SetupScrolling()                  words = "A Quick Brown Insane Fox Jumped Over the Fence and Ziplined to Cover".split()                 self.spSizer = wx.BoxSizer(wx.VERTICAL)                 for word in words:                         text = wx.TextCtrl(self.scrolled_panel, value=word)                         self.spSizer.Add(text)                     self.scrolled_panel.SetSizer(self.spSizer)                 # --------------------                  btn = wx.Button(self.panel, label="Add Widget")                 btn.Bind(wx.EVT_BUTTON, self.onAdd)                  panelSizer = wx.BoxSizer(wx.VERTICAL)                      panelSizer.Add(self.scrolled_panel, 1, wx.EXPAND)                 panelSizer.Add(btn)                         self.panel.SetSizer(panelSizer)                  #----------------------------------------------------------------------             def onAdd(self, event):                     new_text = wx.TextCtrl(self.scrolled_panel, value="New Text")                 self.spSizer.Add(new_text)                 self.scrolled_panel.Layout()                 self.scrolled_panel.SetupScrolling()          # Run the program if __name__ == "__main__":             app = wx.App(False)             frame = MyForm().Show()             app.MainLoop() 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.