MCPcopy Index your code
hub / github.com/python/cpython / VerticalScrolledFrame

Class VerticalScrolledFrame

Lib/idlelib/configdialog.py:2360–2400  ·  view source on GitHub ↗

A pure Tkinter vertically scrollable frame. * Use the 'interior' attribute to place widgets inside the scrollable frame * Construct and pack/place/grid normally * This frame only allows vertical scrolling

Source from the content-addressed store, hash-verified

2358
2359
2360class VerticalScrolledFrame(Frame):
2361 """A pure Tkinter vertically scrollable frame.
2362
2363 * Use the 'interior' attribute to place widgets inside the scrollable frame
2364 * Construct and pack/place/grid normally
2365 * This frame only allows vertical scrolling
2366 """
2367 def __init__(self, parent, *args, **kw):
2368 Frame.__init__(self, parent, *args, **kw)
2369
2370 # Create a canvas object and a vertical scrollbar for scrolling it.
2371 vscrollbar = Scrollbar(self, orient=VERTICAL)
2372 vscrollbar.pack(fill=Y, side=RIGHT, expand=FALSE)
2373 canvas = Canvas(self, borderwidth=0, highlightthickness=0,
2374 yscrollcommand=vscrollbar.set, width=240)
2375 canvas.pack(side=LEFT, fill=BOTH, expand=TRUE)
2376 vscrollbar.config(command=canvas.yview)
2377
2378 # Reset the view.
2379 canvas.xview_moveto(0)
2380 canvas.yview_moveto(0)
2381
2382 # Create a frame inside the canvas which will be scrolled with it.
2383 self.interior = interior = Frame(canvas)
2384 interior_id = canvas.create_window(0, 0, window=interior, anchor=NW)
2385
2386 # Track changes to the canvas and frame width and sync them,
2387 # also updating the scrollbar.
2388 def _configure_interior(event):
2389 # Update the scrollbars to match the size of the inner frame.
2390 size = (interior.winfo_reqwidth(), interior.winfo_reqheight())
2391 canvas.config(scrollregion="0 0 %s %s" % size)
2392 interior.bind('<Configure>', _configure_interior)
2393
2394 def _configure_canvas(event):
2395 if interior.winfo_reqwidth() != canvas.winfo_width():
2396 # Update the inner frame's width to fill the canvas.
2397 canvas.itemconfigure(interior_id, width=canvas.winfo_width())
2398 canvas.bind('<Configure>', _configure_canvas)
2399
2400 return
2401
2402
2403if __name__ == '__main__':

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…