(no subject)

johngrayson at home.com johngrayson at home.com
Wed Apr 4 06:15:10 EDT 2001


--- In python-list at y..., "dsavitsk" <dsavitsk at e...> wrote:
> i have been trying to scroll a canvas widget for weeks now.  if
anybody can offer some suggestions i would be very happy to hear them.
>
> i can get all of the stuff i want to appear, and the scrollbars
move, but the canvas just sits there.
>
> also, PMW (scrolledframe in particular) would be a better solution,
but it doesn't seem to give me control over the scroll bars
programatically or
> allow me to tie one of the scrollbars to 2 scrolled frames. if
anyone can
> help with that it would be great too (even helping me to modify the
> scrolledframe class).
>
> here is some sample code. this version is copied almost verbatim
from john
> shipman's tutorial.  i have other non-working versions if anyone is
> interested in them too ;-)
>
> thanks,
> doug
>


This works. I've made the labels canvas_window objects...

from Tkinter import *

class contain:
    def __init__(self, parent):
        self.f = Frame(parent, width=600, height=400,
                       bg='#ff0000', border=0)
        self.f.pack(expand=NO, anchor=NW)
        self.c = Canvas(self.f, bg='#00ff00', width=600, height=400,
                        scrollregion=(0,0,3100,800))
        self.c.grid(row=0, column=0)
        self.sy = Scrollbar(self.f, orient='vertical',
                            command=self.c.yview)
        self.sy.grid(row=0, column=1, sticky=N+S)
        self.sx = Scrollbar(self.f, orient='horizontal',
                            command=self.c.xview)
        self.sx.grid(row=1, column=0, sticky=E+W)
        self.c['xscrollcommand'] = self.sx.set
        self.c['yscrollcommand'] = self.sy.set

        x=25
        inc = 60
        for i in range(50):
            lbl = Label(self.c, text='label # %d' % i,
        relief=RIDGE)
            self.c.create_window(x, 25, window=lbl, anchor = CENTER)
            x = x+inc

if __name__ == '__main__':
root = Tk()
x = contain(root)
mainloop()


John Grayson  (Python and Tkinter Programming)






More information about the Python-list mailing list