473,231 Members | 1,694 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

scrollbar dependencies

Hello.

I am using Tkinter and Pmw.
I would like to build 2 canvases/frames that are scrollable together
horizontally, and independently vertically (so, the vertical
scrollbars should not be moved by the horizontal one).

So I built a Pmw.ScrolledFrame() containing the 2 canvases,
horizontally scrollable. Now I am trying to build 2 independent
vertical scrollbars,
--> wich command is linked to each canvas (whose parent is
Pmw.ScrolledFrame.component('frame'),
--> and which parent is root (to be packed outside the Pmw.ScrolledFrame).

Is this possible or not ? If not, does somebody allready did that another way ?

Thanks a lot.

Marion.
Jul 18 '05 #1
7 1418
On 3 Mar 2005 01:06:48 -0800, Marion <su**********@gmail.com> wrote:
Hello.

I am using Tkinter and Pmw.
I would like to build 2 canvases/frames that are scrollable together
horizontally, and independently vertically (so, the vertical
scrollbars should not be moved by the horizontal one).

So I built a Pmw.ScrolledFrame() containing the 2 canvases,
horizontally scrollable.
I'd not go that way: a Pmw.ScrolledFrame is not supposed to be used this way, and you may have great troubles making it work as you want...

[snip] Is this possible or not ? If not, does somebody allready did that another way ?


Here is a solution using only pure-Tkinter:

--DualCanvas.py--------------------------------------------------
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(*args):
c1.xview(*args)
c2.xview(*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')

vScroll2 = Scrollbar(orient=VERTICAL, command=c2.yview)
vScroll2.grid(row=1, column=1, sticky='ns')

## Associate scrollbars to canvases
c1.configure(xscrollcommand=hScroll.set, yscrollcommand=vScroll1.set)
c2.configure(xscrollcommand=hScroll.set, yscrollcommand=vScroll2.set)

## Put a few things in canvases so that we see what's going on
c1.create_oval(80, 80, 120, 120, fill='red')
c1.create_oval(380, 80, 420, 120, fill='red')
c1.create_oval(80, 380, 120, 420, fill='red')
c1.create_oval(380, 380, 420, 420, fill='red')

c2.create_oval(80, 80, 120, 120, fill='blue')
c2.create_oval(380, 80, 420, 120, fill='blue')
c2.create_oval(80, 380, 120, 420, fill='blue')
c2.create_oval(380, 380, 420, 420, fill='blue')

## Go!
root.mainloop()
-----------------------------------------------------------------

The "trick" is simply to create a function accepting the same arguments as the xview methods on canvases and forward these arguments to the xview methods of both canvases. You then pass this function to the command option of both scrollbars, and voilà. The link canvas -> scrollbar is done the usual way.

HTH
--
python -c 'print "".join([chr(154 - ord(c)) for c in "U(17zX(%,5.z^5(17l8(%,5.Z*(93-965$l7+-"])'
Jul 18 '05 #2
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

Jul 18 '05 #3
On 3 Mar 2005 02:38:59 -0800, Harlin Seritt <ha**********@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.htm...00000000000000

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.
--
python -c 'print "".join([chr(154 - ord(c)) for c in "U(17zX(%,5.z^5(17l8(%,5.Z*(93-965$l7+-"])'
Jul 18 '05 #4
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,xscrollcomma nd=hScroll.set)

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

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

"Eric Brunel" <er*********@despammed.com> wrote in message news:<op**************@eb.pragmadev>...
On 3 Mar 2005 02:38:59 -0800, Harlin Seritt <ha**********@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.htm...00000000000000

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.

Jul 18 '05 #5
Next mystery :
a picture drawn in the canvas c1 is scrollable.
a picture-containing canvas "grided" in the canvas c1 is not.

so why ???
Marion
---------------------------------------------------------------
from tkinter import *
from PIL import *

class Main:
def __init__(self):
## Main window
self.root = Tk()
self.root.grid_rowconfigure(0, weight=1)
self.root.grid_rowconfigure(1, weight=1)
self.root.grid_columnconfigure(0, weight=1)
## datas :
self.PIC=[]
self.ANN=[]

## First canvas (picture)
self.c1 = Canvas(
self.root,
width=500,
height=100,
bd=2,
relief=SUNKEN,
scrollregion=(0, 0, 100, 100))

self.c1.grid(
row=0,rowspan=2,
column=1,
sticky='nswe')

#-------------------------------#
# this is scrollable :
#-------------------------------#
image =Image.new("RGB",(100,100))
dessin = ImageDraw.Draw(image)
dessin.rectangle([(10,10),(50,50)],fill="rgb(255,0,0)")
photo=ImageTk.PhotoImage(image)
item = self.c1.create_image(0,0,anchor=NW,image=photo)

#-------------------------------#
# this is not ! :
#-------------------------------#
canvas=Canvas(self.c1,background="WHITE")
image =Image.new("RGB",(100,100))
dessin = ImageDraw.Draw(image)
dessin.rectangle([(10,10),(50,50)],fill="rgb(255,0,0)")
photo=ImageTk.PhotoImage(image)
item = canvas.create_image(0,0,anchor=NW,image=photo)
canvas.grid()
## Second canvas (annot)
c2 = Canvas(
self.root,
width=500,
height=100,
bd=2,
relief=SUNKEN,
scrollregion=(0, 0, 1000, 1000))
c2.grid(
row=2,rowspan=2,
column=1,
sticky='nswe')

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

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

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

vScroll2 = Scrollbar(orient=VERTICAL, command=c2.yview)
vScroll2.grid(
row=2,rowspan=2,
column=2,
sticky='ns')
c2.config(yscrollcommand=vScroll2.set,xscrollcomma nd=hScroll.set)
---------------------------------------------------------------
Jul 18 '05 #6
On 24 Mar 2005 03:24:34 -0800, Marion <su**********@gmail.com> wrote:
Next mystery :
a picture drawn in the canvas c1 is scrollable.
a picture-containing canvas "grided" in the canvas c1 is not.

so why ???
Marion
--------------------------------------------------------------- [snip] #-------------------------------#
# this is not ! :
#-------------------------------#
canvas=Canvas(self.c1,background="WHITE")
image =Image.new("RGB",(100,100))
dessin = ImageDraw.Draw(image)
dessin.rectangle([(10,10),(50,50)],fill="rgb(255,0,0)")
photo=ImageTk.PhotoImage(image)
item = canvas.create_image(0,0,anchor=NW,image=photo)
canvas.grid()


You don't want to do that. Canvases are not meant to be containers where you can pack or grid items. They strangely accept it, but it will never do what you want. If you want to pack or grid items in a container, use a Frame. If you want to include a widget in a Canvas, use a canvas window:
c1 = Canvas(root)
c1.pack()
c2 = Canvas(c1, bd=2, relief=SUNKEN, width=50, height=50)
c1.create_window(20, 20, window=c2, anchor=NW)


Canvas windows are scollable; widgets packed or gridded in Canvases are not. So this really seems to be your problem here.

HTH
--
python -c 'print "".join([chr(154 - ord(c)) for c in "U(17zX(%,5.z^5(17l8(%,5.Z*(93-965$l7+-"])'
Jul 18 '05 #7
ok, we must redefine each canvas scroll individually ... but what a ()
strange language... !!
Jul 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Sujan | last post by:
Hello all, Is it possible to remove scrollbar(s) without using frames. Is there any code which could be applied in body tag to remove scrollbar(s). Thanks in adv, Sujan
4
by: Price Brattin | last post by:
I dragged a datagrid onto a VB.Net WinForm and used the properties page and a few lines of code to set it up, including the DataSource. No wizard setup was used. It works fine except for one...
9
by: kjs | last post by:
Is there any was to control the color of the scrollbars when using the 'overflow: scroll' attribute? TIA, Karl
0
by: h-h | last post by:
BODY { scrollbar-face-color: #f5f5f5; scrollbar-highlight-color: #666666; scrollbar-shadow-color: #666666; scrollbar-3dlight-color: #ffffff; scrollbar-arrow-color: #666666;...
1
by: Shun | last post by:
Hello, How to the add a blue color scrollbar to the browser Left and bottom. Thanx Shun
0
by: d.steininger | last post by:
Hi there! Is there a way to bind a Textbox.Text to a ScrollBar.Value (not the Textbox-own Scrollbar) and vice versa? The Problem: I have to deal with two controls. The Textbox should accept...
2
by: kurt sune | last post by:
How do I render the scrollbars by CSS in a listbox? I have understood that an asp listbox gets rendered as a select element. So I tried first by adding a style element: ..TA...
3
by: nicky77 | last post by:
Hi, before you say it i know frames are bad practice - but i'm developing dynamic content on a site which has already been designed, so alas there's no option but to use them. Anyway, I just want to...
1
by: Tom | last post by:
First, I posted a similar request for help in another group and now don't find the posting. Problem with my newsreader perhaps ... but apologies if this appears as a cross posting. My code is...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.