[ python-l ] scrolling a frame

Toph toph at laposte.net
Wed Dec 3 09:59:58 CET 2003


Hi,

I am developing a software in Python using Tkinter. The choice of my team is not to use pyton MegaWidgets.
I would like to scroll a frame.

This is a peace of my code :
# -----------------------------------------------------------------------------
#!/bin/env python
from Tkinter import *

root = Tk()
global_frame = Frame(root, relief = GROOVE, borderwidth=4)
canvas = Canvas(global_frame)

# scrollbars: 

vscroll = Scrollbar(global_frame, command=canvas.yview)
hscroll = Scrollbar(global_frame, command=canvas.xview, orient=HORIZONTAL)


# The frame i want to scroll : 
frame = Frame(canvas, relief = GROOVE, borderwidth=2)
cw = canvas.create_window(0,0, window = frame)


global_frame.grid(row = 0, column = 0, sticky=NS)

#put the widgets in global_frame
canvas.grid(row = 0, column = 0)
vscroll.grid(row = 0, column = 1, sticky=NS)
hscroll.grid(row = 1, column = 0, sticky=EW)

# fill the frame : 
for item in range(30):
Label(frame, text = 'item %d'%item).grid(row = item,
column = 0)
Entry(frame, text = 'default text %d'%item).grid(row = item,
column = 1, sticky=EW)

# configure the scollbars to scroll the canvas :
hauteur = frame.winfo_height()
largeur = frame.winfo_width()
canvas.configure(yscrollcommand = vscroll.set, xscrollcommand = hscroll.set,
scrollregion = (0,0, largeur, hauteur)) #canvas.coords(cw))

# My problem is that i would like the scrollregion to scroll only the space taken by 

# the frame but my program does not do it well...

root.mainloop()
#------------------------------------------------------------------------------

I thank you in advance.

Christophe

Accédez au courrier électronique de La Poste : www.laposte.net ; 
3615 LAPOSTENET (0,34€/mn) ; tél : 08 92 68 13 50 (0,34€/mn)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20031203/c12f57aa/attachment.html>


More information about the Python-list mailing list