Re: tkinter canvas

Discussion in 'Python' started by John McMonagle, Apr 5, 2006.

  1. 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.
    John McMonagle, Apr 5, 2006
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?ISO-8859-1?Q?Mickel_Gr=F6nroos?=

    Placing entry widgets on a canvas in Tkinter

    =?ISO-8859-1?Q?Mickel_Gr=F6nroos?=, Jun 30, 2003, in forum: Python
    Replies:
    0
    Views:
    418
    =?ISO-8859-1?Q?Mickel_Gr=F6nroos?=
    Jun 30, 2003
  2. =?ISO-8859-1?Q?Mickel_Gr=F6nroos?=

    Re: Placing entry widgets on a canvas in Tkinter

    =?ISO-8859-1?Q?Mickel_Gr=F6nroos?=, Jun 30, 2003, in forum: Python
    Replies:
    0
    Views:
    962
    =?ISO-8859-1?Q?Mickel_Gr=F6nroos?=
    Jun 30, 2003
  3. Askari
    Replies:
    2
    Views:
    708
    Askari
    Aug 30, 2004
  4. PhilC
    Replies:
    2
    Views:
    883
    PhilC
    Oct 25, 2004
  5. Replies:
    10
    Views:
    260
    Rick Johnson
    Mar 15, 2013
Loading...

Share This Page