How to create a scrolled window (Phoenix)

Keywords : Scrolled window.


Introduction :

This is one of the container widgets.

It can be useful, when we have a larger area than a window can display.

In our example, we demonstrate such a case.

We place a large image into our window.

When the window is smaller than our image, Scrollbars are displayed automatically.

wx.ScrolledWindow methods

SetScrollbars()

set scrollbars for a window

Scroll(int x, int y)

scroll a window

int GetScrollPageSize(int orient)

get the scroll page size

SetScrollPageSize(int orient, int pageSize)

set the scroll page size

SetScrollRate(int xstep, int ystep)

set scrolling rate

wx.Size GetScrollPixelsPerUnit()

get the size of one logical unit in physical units

SetScrollRate(int xstep, int ystep)

set scrolling rate

EnableScrolling(bool x, bool y)

enable or disable scrolling

wxPoint GetViewStart()

get the view start

SetTargetWindow(wx.Window target)

set the target window for scrolling

wx.Window GetTargetWindow()

get the scrolling target window

AdjustScrollbars()

adjust scrollbars

(info by ZetCode / Jan Bodnar).


Demonstrating :

Tested py3.x, wx4.x and Win10.

Are you ready to use some samples ? ;)

Test, modify, correct, complete, improve and share your discoveries ! (!)


Sample one

img_sample_one.png

   1 # sample_one.py
   2 
   3 """
   4 
   5 Author : Jan Bodnar
   6 Website : zetcode.com
   7 
   8 """
   9 
  10 import wx
  11 
  12 # class MyFrame
  13 # class MyApp
  14 
  15 #---------------------------------------------------------------------------
  16 
  17 class MyFrame(wx.Frame):
  18     def __init__(self, parent, id, title):
  19         wx.Frame.__init__(self, parent, id, title, size=(500, 400))
  20 
  21         self.SetIcon(wx.Icon('./icons/icon_wxWidgets.ico', wx.BITMAP_TYPE_ICO))
  22 
  23         #------------
  24 
  25         sw = wx.ScrolledWindow(self)
  26 
  27         bmp = wx.Image('./bitmaps/aliens.jpg', wx.BITMAP_TYPE_JPEG).ConvertToBitmap()
  28         wx.StaticBitmap(sw, -1, bmp)
  29 
  30         sw.SetScrollbars(20, 20, 55, 40)
  31 
  32         #------------
  33 
  34         self.Bind(wx.EVT_CLOSE, self.OnClose)
  35 
  36     #-----------------------------------------------------------------------
  37 
  38     def OnClose(self, event):
  39         self.Destroy()
  40         wx.Exit()
  41 
  42 #---------------------------------------------------------------------------
  43 
  44 class MyApp(wx.App):
  45     def OnInit(self):
  46        frame = MyFrame(None, -1, 'wx.ScrolledWindow')
  47        frame.Centre()
  48        frame.Show(True)
  49 
  50        return True
  51 
  52 #---------------------------------------------------------------------------
  53 
  54 app = MyApp(0)
  55 app.MainLoop()


Download source

source.zip


Additional Information

Link :

- - - - -

https://wiki.wxpython.org/TitleIndex

https://docs.wxpython.org/


Thanks to

Jan Bodnar (sample_one.py coding), the wxPython community...


About this page

Date(d/m/y) Person (bot) Comments :

28/12/20 - Ecco (Created page for wxPython Phoenix).


Comments

- blah, blah, blah....

How to create a scrolled window (Phoenix) (last edited 2020-12-28 14:54:10 by Ecco)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.