4

I have a fairly large size GUI built in tkinter using the grid manager method. I need to add a scrollbar to the entire window and Im having some trouble. Here is a very crude version of a scroll-bar using the grid manager in Tkinter (i dont want to scroll the list box, i want to scroll the entire Tk window).

import Tkinter
from Tkinter import *

Tk = Tkinter.Tk
self=Tk()
listbox = Listbox(self, width = 10, height = 60)
listbox.grid(row =0, column=0)
scrollbar = Scrollbar(self)
scrollbar.grid(sticky=E, row = 0, rowspan = 100, column = 11, ipady = 1000)
mainloop()

Is it possible to fix the Tkinter window size (using grid manager) and add a scrollbar which then allows the user to view additional content? The window is too large and additional content needs to be viewed so the only option i see is a scrollbar. I only see examples using the pack method. As you can probably guess I am new to Tkinter and would appreciate any input.

Thanks to all in advance.

user2860797
  • 173
  • 1
  • 3
  • 11
  • possible duplicate of [Python Tkinter scrollbar for frame](http://stackoverflow.com/questions/16188420/python-tkinter-scrollbar-for-frame) – Bryan Oakley Jan 13 '14 at 11:49

1 Answers1

3

You cannot scroll the entire contents of a root window, a Toplevel window, or a Frame. The solution is to put all of your widgets in a canvas, and then add a scrollbar to the canvas. There are questions on this site that give examples, such as Python Tkinter scrollbar for frame

Community
  • 1
  • 1
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • So if I am using the .grid method or grid manager to layout all GUI widgets, I have to convert the GUI using a canvas and the .pack method? Is there anyway to add a button which would just move the view of the root to the bottom edge (im guessing not)? I was hoping to avoid restructuring the entire project. Thanks for your help. – user2860797 Jan 13 '14 at 16:28
  • 1
    @user2860797: not exactly. You still use grid to lay out all your widgets in a frame. Instead of putting them directly in the root, put them in a frame. Then, you put that frame in a canvas so you can scroll it. So instead of root.listbox you'll end up with root.canvas.frame.listbox. It sounds complicated but it's not. – Bryan Oakley Jan 13 '14 at 17:27