Tkinter: scrolling the canvas items AND widgets

jmdeschamps jmdeschamps at cvm.qc.ca
Thu Sep 19 22:55:06 CEST 2002


I'm trying to use canvas as a scrollable region to make dynamic entry
forms (variable number of Entry fields).
I would like to be able to scroll down the canvas if the fields go
outside the visible region using scrollbars :)
This code lets me scroll the graphical items but the widgets stay put
using PythonWin 2.2.1 on Windows 2000
*********
import Tkinter

root = Tkinter.Tk()

# Create widgets
canvas = Tkinter.Canvas(root)
canvas.pack(side=LEFT)
# Vertical scroll bar
verticalScrollbar = Tkinter.Scrollbar(root)                       
verticalScrollbar.pack(side=LEFT,expand=1,fill=Y)          
                                                           
# Configure
root.rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)
canvas.config(   height = 300,                    
    scrollregion = (0, 0, 100, 1000),
    yscrollcommand=verticalScrollbar.set )
verticalScrollbar.config(
    orient=Tkinter.VERTICAL,
    command = canvas.yview)
                                
# Draw on canvas
canvas.create_polygon(10, 10, 300, 50, 10, 100)
#Add widgets
for i in range(1):
    f=Entry(canvas)
    f.place(x=10,y=10)

root.mainloop()
**** end code *******

With this, I can scroll the polygon but not the Entry field ???

Thanks in advance,

Jean-Marc



More information about the Python-list mailing list