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.

1

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

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: 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.