473,396 Members | 2,113 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,396 software developers and data experts.

'int' object has no attribute 'delete'

Hey. Im working on this for a school project thing and i need some help please.

Expand|Select|Wrap|Line Numbers
  1.  
  2. from Tkinter import*
  3. import random
  4. import time
  5.  
  6. number = 5
  7. i = 0
  8.  
  9. class Test():
  10.     def __init__(self):
  11.         i=0
  12.         self.root = Tk()
  13.         self.root.title('Test')
  14.  
  15.         self.can = Canvas(self.root, width= 800, height = 600, bg='Blue')
  16.         self.can.grid()
  17.  
  18.         self.b = Button(self.root, width=25, height = 5, text="START TEST", command=self.countdown)
  19.         self.b.grid(column=0, row=0)
  20.  
  21.         self.root.mainloop()
  22.  
  23.  
  24.  
  25.  
  26.     def countdown(self):
  27.         global i
  28.         global number
  29.  
  30.         if i == 0:
  31.             self.b.destroy()
  32.  
  33.             self.text=self.can.create_text(400, 300, text='TEST STARTS IN...')
  34.             i+=1
  35.             self.countdown()
  36.         elif i>0 and i<6:
  37.             self.text=self.can.create_text(400, 325, text=number)
  38.             time.sleep(1)
  39.             self.text.delete()
  40.             self.root.update()
  41.             number=number-1
  42.             self.countdown()
  43.         else:
  44.             pass
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51. Test()
  52.  
  53.  
  54.  
Thank you.
Apr 8 '09 #1
5 9776
bvdet
2,851 Expert Mod 2GB
I know very little about Tkinter. I was able to get the script to work by making some changes. First, get rid of the global variables number and i. In many cases, global variables are unnecessary and their use is typically discouraged. Second, eliminate the recursive calls to self.countdown(). Third, the delete() method is a canvas method, not a method of the text ID, which is an integer. Fourth, use a for loop to make the countdown.
Expand|Select|Wrap|Line Numbers
  1.         self.b.destroy()
  2.         for i in range(6, 0, -1):
  3.             if i == 6:
  4.                 ** do stuff **
  5.             else:
  6.                 ** do other stuff **
  7.         self.root.destroy()
I added the destroy() method to close the canvas window, but you may need to do something else. Since this is a school project, I won't provide the complete code.

-BV
Apr 8 '09 #2
thank you! that helps a lot. :)
Apr 17 '09 #3
@bvdet
Ok, i did everything else and i have gotten it to where it will do the countdown with the loop and no globals and everything. Only problem im still having is i dont know how to get the text off the canvas. It stays on and when i try to delete it off the canvas it gives me that error again. Sorry but can you help me get it to where i can delete every number before the next one comes up. Thanks.
May 1 '09 #4
bvdet
2,851 Expert Mod 2GB
Use canvas method delete().
Expand|Select|Wrap|Line Numbers
  1.         self.text2=self.can.create_text(400, 325, text=str(i))
  2.         self.root.update()
  3.         time.sleep(1)
  4.         self.can.delete(self.text2)
-BV
May 1 '09 #5
oh duh. lol. thanks! :)
May 4 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Roy Smith | last post by:
For the past 6-8 months, I've spent most of my time writing C++ and a little bit of Java. Both of these languages support and encourage the use of private data and explicit accessor functions,...
18
by: Steven Bethard | last post by:
In the "empty classes as c structs?" thread, we've been talking in some detail about my proposed "generic objects" PEP. Based on a number of suggestions, I'm thinking more and more that instead of...
1
by: BCS | last post by:
I have a table called BOLDetail and I need to update a column called "Tons" from int to decimal with a precision of 5 and scale of 3. I attempted to change the setting in Table Design but received...
21
by: Andreas Huber | last post by:
Hi there Spending half an hour searching through the archive I haven't found a rationale for the following behavior. using System; // note the missing Flags attribute enum Color {
10
by: Piotr | last post by:
I have a class 'Statistics' which has a private attribute ' vector<int>* _x;' And in the destructor of the Statistics, I have this code to free the memory: Statistics::~Statistics() { if...
3
by: Eric Mahurin | last post by:
Is there a standard way to get a descriptor object for an arbitrary object attribute - independent of whether it uses the descriptor/ property protocol or not. I want some kind of...
18
by: subramanian100in | last post by:
Consider a class that has vector< pair<int, string>* c; as member data object. I need to use operator>to store values into this container object and operator<< to print the contents of the...
6
by: Kindler Chase | last post by:
I'm trying to iterate through a set of nodes and then edit/delete specific attributes using XPathNodeIterator. Adding attributes is no problem. My first question is how do I delete an attribute...
16
by: Stefano Sabatini | last post by:
Hi all, I'm facing this design problem. I have a table which defines the behaviour of an Object in a given state according to the type of event it is receiving. So for each couple...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.