scrollbar dependencies

Marion supermarion3 at gmail.com
Wed Mar 23 06:19:25 EST 2005


Thanks a lot, Eric Brunel.
Harlin, if it's still actual (don't think so, but whoever...) here is
a simple code that works.
---------------------------------------
from Tkinter import *

## Main window
root = Tk()
root.grid_rowconfigure(0, weight=1)
root.grid_rowconfigure(1, weight=1)
root.grid_columnconfigure(0, weight=1)

## First canvas
c1 = Canvas(root, width=200, height=100, bd=2, relief=SUNKEN,
                   scrollregion=(0, 0, 500, 500))
c1.grid(row=0, column=0, sticky='nswe')

## Second canvas
c2 = Canvas(root, width=200, height=100, bd=2, relief=SUNKEN,
                   scrollregion=(0, 0, 500, 500))
c2.grid(row=1, column=0, sticky='nswe')

## Special function scroll both canvases horizontally
def xscrollboth(self,*args):
    c1.xview(self,*args)
    c2.xview(self,*args)

## Horizontal scrollbar for both canvases
hScroll = Scrollbar(root, orient=HORIZONTAL, command=xscrollboth)
hScroll.grid(row=2, column=0, sticky='we')

## Vertical scrollbars
vScroll1 = Scrollbar(orient=VERTICAL, command=c1.yview)
vScroll1.grid(row=0, column=1, sticky='ns')
c1.config(yscrollcommand=vScroll1.set,xscrollcommand=hScroll.set)

vScroll2 = Scrollbar(orient=VERTICAL, command=c2.yview)
vScroll2.grid(row=1, column=1, sticky='ns')
c2.config(yscrollcommand=vScroll2.set,xscrollcommand=hScroll.set)

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

"Eric Brunel" <eric_brunel at despammed.com> wrote in message news:<opsm177d1crqur0o at eb.pragmadev>...
> On 3 Mar 2005 02:38:59 -0800, Harlin Seritt <harlinseritt at yahoo.com> wrote:
> 
> > Pardon a question I should already know the answer to, but what are the
> > *args in the:
> >
> > def xscrollboth(*args):
> >    c1.xview(*args)
> >    c2.xview(*args)
> >
> > Thanks,
> >
> > Harlin
> 
> If your question is about the syntax, it's just the way of passing any number of arguments to a function as explained in:
> http://docs.python.org/tut/node6.html#SECTION006730000000000000000
> 
> If your question is about what will actually be passed in these arguments, the answer is simply: I don't know, and I don't care. That's why I used a *args: I just want to pass to the c1.xview and c2.xview methods exactly what was passed to my xscrollboth function. Since Python allows me to just pass the list of arguments unchanged, I happily do it.



More information about the Python-list mailing list