Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: tkinter canvas

Reply
Thread Tools

Re: tkinter canvas

 
 
John McMonagle
Guest
Posts: n/a
 
      04-04-2006
On Tue, 2006-04-04 at 14:47 -0700, fxe wrote:
> Hi,
> I am using tkinter and I have a canvas that with several rectangles drawn
> on it. The rectangles need to have bindings to move and resize them. No
> problem here, but I also need to display a grid on the same canvas, for
> which I am using create_line. My problem is I do not want the grid lines to
> be able to move and resize .
>
> Is this doable or any suggestions on an alternative.Maybe another way to
> display my grid on top of the canvas?
>


When you create your canvas items use the tags option to differentiate
items you wish to group together.

For example,

canvas.create_line(x1,y1,x2,y2,fill='#000000',tags ='grid')

canvas.create_rectangle(x1,y1,x2,y2,fill='#FF0000' ,outline='#FF0000',tags='rect')

You can ensure that the grid lines are always displayed below the
rectangles by using the tag_lower method:

canvas.tag_lower('grid', 'rect')

You can bind events to the named tags rather than the canvas as a whole:

canvas.tag_bind('rect', '<Button-1>', startMove)
canvas.tag_bind('rect', '<Button1-Motion>', moveRect)
canvas.tag_bind('rect', '<Button1-ButtonRelease>', finishMove)

Now when you click on a canvas item with a 'grid' tag nothing will
happen, but if you click on a canvas item with a 'rect' tag you will
invoke the appropriate function.

HTH,

John McMonagle



--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to couper contenier of a canvas in an outer canvas??? olsr.kamal@gmail.com Python 10 03-15-2013 08:46 PM
Canvas with scrollbars - how to get correct canvas coordinate when the scroll bars have moved? PhilC Python 2 10-25-2004 11:57 AM
Canvas scrolling - scrollBar become "disabled" on change in canvas Askari Python 2 08-30-2004 02:56 PM
Re: Placing entry widgets on a canvas in Tkinter =?ISO-8859-1?Q?Mickel_Gr=F6nroos?= Python 0 06-30-2003 01:02 PM
Placing entry widgets on a canvas in Tkinter =?ISO-8859-1?Q?Mickel_Gr=F6nroos?= Python 0 06-30-2003 12:34 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57