#Simple example that puts gui widgets into a frame #and puts the frame into a canvas so that it can be #scrolled. from tkinter import * root = Tk() #Add a canvas to the window canvas = Canvas(root,width=200, height=200) canvas.grid(column=0, row=0, sticky=N+S+E+W) #Allow the canvas (in row/column 0,0) #to "grow" to fill the entire window. root.grid_rowconfigure(0, weight=1) root.grid_columnconfigure(0, weight=1) #Add a scrollbar that will scroll the canvas vertically vscrollbar = Scrollbar(root) vscrollbar.grid(column=1, row=0, sticky=N+S) #Link the scrollbar to the canvas canvas.config(yscrollcommand=vscrollbar.set) vscrollbar.config(command=canvas.yview) #Add a scrollbar that will scroll the canvas horizontally hscrollbar = Scrollbar(root, orient=HORIZONTAL) hscrollbar.grid(column=0, row=1, sticky=E+W) canvas.config(xscrollcommand=hscrollbar.set) hscrollbar.config(command=canvas.xview) #This frame must be defined as a child of the canvas, #even though we later add it as a window to the canvas f = Frame(canvas) # #f.rowconfigure(1, weight=1) #f.columnconfigure(1, weight=1) #Create a button in the frame. b = Button(f,text="hi there") b.grid(row=0, column=0) #Add a large grid of sample label widgets to fill the space for x in range(1,30): for y in range(1,20): Label(f, text=str(x*y)).grid(row=1+y, column=x) #Add the frame to the canvas canvas.create_window((0,0), anchor=NW, window=f) #IMPORTANT: #Unless you want to bind an event handler to be called #when the frame's geometry manager finishes calculating #the frame size you need to call f.update_idletasks() so #that the call to f.bbox() on the following line will #return the correct bounding box size f.update_idletasks() #Tell the canvas how big of a region it should scroll #The size of the frame. canvas.config(scrollregion= f.bbox("all") ) mainloop()