473,378 Members | 1,555 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,378 software developers and data experts.

Tkinter weirdness item count

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
Jul 19 '05 #1
3 2216

"phil" <ph***********@anvilcom.com> wrote in message
news:ma*************************************@pytho n.org...
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
Jul 19 '05 #2
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

Jul 19 '05 #3
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

Jul 19 '05 #4

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

Similar topics

2
by: Zhang Le | last post by:
Hello, Is there a quick way to replace the content of a single item in tkinter's listbox? Currently my solution is to first delete the item, then insert a new item at the same position. I think...
4
by: steve | last post by:
In a nutshell, my problem is that I am getting this runtime error, and I have no clue why. Please bear in mind its my first python program: "localvariable 'currentAbility' referenced before...
3
by: Harlin Seritt | last post by:
I've created a ghetto-ized ComboBox that should work nicely for Tkinter (unfortunately no dropdown capabilities yet). I've found why it's such a pain in the @ss to create one. You have to...
0
by: phil | last post by:
>> 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 Yes, I will...
2
by: Andrew Trevorrow | last post by:
Our app uses embedded Python to allow users to run arbitrary scripts. Scripts that import Tkinter run fine on Windows, but on Mac OS X there is a serious problem. After a script does "root = Tk()"...
3
by: vedran_dekovic | last post by:
Hi, I need help about Tkinter listbox widget.I want,when somebody click on any item(file) in Listbox,then in new Label widget text must be selected item from server. my program (wrong...
1
by: alivip | last post by:
I integrat program to be GUI using Tkinter I try browser direction as you can see # a look at the Tkinter Text widget # use ctrl+c to copy, ctrl+x to cut selected text, # ctrl+v to...
3
by: J-Burns | last post by:
Hello. Im a bit new to using Tkinter and im not a real pro in programming itself... :P. Need some help here. Problem 1: How do I make something appear on 2 separate windows using Tkinter? By...
4
by: Mudcat | last post by:
I've tried quite a few things to get this correct but have hit a couple of sticking points that I can't figure out. I need to ge the Text box to function like the 'wraplength' option in a Label. ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.