Tkinter weirdness item count

Discussion in 'Python' started by phil, Apr 29, 2005.

  1. phil

    phil Guest

    Using Tkinter Canvas to teach High School Geometry
    with A LOT of success.

    My drawing gets very slow after a lot of actions.

    For instance I have created code to rotate a set of objects
    about a rotation point.
    rotate 360 degrees starts to get slow
    after 720 degrees its crawling.

    I checked the item list with with find_all: IT GROWS!

    OK, I create 3 lines using a line Class I created.
    When I rotate these 3 lines thru 360 degrees it creates
    360 lines times 3. But each new instance of line REPLACES
    the old instance. The line class has a destructor to delete
    the drawn object.

    class line:
    count = 0
    def __init__(s,glob,argl,color=''):
    line.count = line.count + 1
    ##
    ## buncha code here
    ##
    s.obj = glob.can.create_line(x0,y0,x1,y1,
    width=glob.width,fill=s.color)
    def __del__(s):
    line.count = line.count - 1

    ## delete the line object if the
    ## class instance is deleted
    s.glob.can.delete(s.obj)


    After the rotation I check line.count and it is 3
    But find_all returns a tuple ofover 1000 items.
    The drawn objects are not being deleted.
    Which is kinda weird because the rotation works.
    That is they appear to be deleted.

    Is find_all() fooling me?
    Is this the reason drawing slows down? Is it refreshing
    invisible objects?

    This slowing down also occurs when I draw a lot of objects.
    Lets say I draw a sine wave, say 1000 individual points.
    If I draw 4 or 5 sine waves it gets really slow.

    I should mention I call update() after each drawing action.
    This is necessary for the students to watch the progress.
    I might be drawing objects in a lengthy loop and without
    update() they only appear at the end of the loop.

    Thanks for any help.

    -- Confused
    phil, Apr 29, 2005
    #1
    1. Advertising

  2. phil

    David Isaac Guest

    "phil" <> wrote in message
    news:...
    > Using Tkinter Canvas to teach High School Geometry
    > with A LOT of success.



    Can you post a link to your code.
    I'd like to see what you are doing.

    Thx,
    Alan Isaac
    David Isaac, Apr 30, 2005
    #2
    1. Advertising

  3. phil

    Peter Otten Guest

    phil wrote:

    > def __del__(s):
    > line.count = line.count - 1
    >
    > ## delete the line object if the
    > ## class instance is deleted
    > s.glob.can.delete(s.obj)
    >
    >
    > After the rotation I check line.count and it is 3


    Did you know that exceptions are ignored in the __del__() method?
    One way to verify that your __del__() runs to completion would be to make
    the line.count decrement the last statement, and check the total line.count
    after the rotation again.
    Generally speaking the __del__() method is not the most robust cleanup
    mechanism. Maybe you can add a line.delete() method and change your program
    flow for it to be called explicitly when the line should no longer be
    visible.

    Peter
    Peter Otten, May 1, 2005
    #3
  4. phil

    pavel.kosina Guest

    I think the answer you should find under Subject: Tkinter slowes down


    ---
    geon
    Exception is rule.

    phil napsal(a):
    > Using Tkinter Canvas to teach High School Geometry
    > with A LOT of success.
    >
    > My drawing gets very slow after a lot of actions.
    >
    > For instance I have created code to rotate a set of objects
    > about a rotation point.
    > rotate 360 degrees starts to get slow
    > after 720 degrees its crawling.
    >
    > I checked the item list with with find_all: IT GROWS!
    >
    > OK, I create 3 lines using a line Class I created.
    > When I rotate these 3 lines thru 360 degrees it creates
    > 360 lines times 3. But each new instance of line REPLACES
    > the old instance. The line class has a destructor to delete
    > the drawn object.
    >
    > class line:
    > count = 0
    > def __init__(s,glob,argl,color=''):
    > line.count = line.count + 1
    > ##
    > ## buncha code here
    > ##
    > s.obj = glob.can.create_line(x0,y0,x1,y1,
    > width=glob.width,fill=s.color)
    > def __del__(s):
    > line.count = line.count - 1
    >
    > ## delete the line object if the
    > ## class instance is deleted
    > s.glob.can.delete(s.obj)
    >
    >
    > After the rotation I check line.count and it is 3
    > But find_all returns a tuple ofover 1000 items.
    > The drawn objects are not being deleted.
    > Which is kinda weird because the rotation works.
    > That is they appear to be deleted.
    >
    > Is find_all() fooling me?
    > Is this the reason drawing slows down? Is it refreshing
    > invisible objects?
    >
    > This slowing down also occurs when I draw a lot of objects.
    > Lets say I draw a sine wave, say 1000 individual points.
    > If I draw 4 or 5 sine waves it gets really slow.
    >
    > I should mention I call update() after each drawing action.
    > This is necessary for the students to watch the progress.
    > I might be drawing objects in a lengthy loop and without
    > update() they only appear at the end of the loop.
    >
    > Thanks for any help.
    >
    > -- Confused
    >
    >
    pavel.kosina, May 29, 2005
    #4
    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. Praveen Balanagendra via .NET 247
    Replies:
    2
    Views:
    4,088
  2. Alex
    Replies:
    1
    Views:
    475
    gsnke
    May 26, 2005
  3. steve
    Replies:
    4
    Views:
    523
    Brian van den Broek
    Mar 13, 2005
  4. phil

    Tkinter weirdness item count

    phil, May 1, 2005, in forum: Python
    Replies:
    0
    Views:
    313
  5. efelnavarro09
    Replies:
    2
    Views:
    929
    efelnavarro09
    Jan 26, 2011
Loading...

Share This Page