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

int object has no attribute 'destroy'...why is this happening? Please help

Expand|Select|Wrap|Line Numbers
  1. from tkinter import *
  2. import time
  3. import random
  4.  
  5. # Set up Root
  6. root=Tk()
  7. root.geometry("1200x1000")
  8. root.title("Aliens Attack!!")
  9.  
  10. # Set up Global variables
  11.  
  12. global score
  13. score=0
  14.  
  15. global lives
  16. lives=3
  17.  
  18. global myRandom1
  19. myRandom1=150
  20.  
  21. global myRandom2
  22. myRandom2=300
  23.  
  24. global alienNumber
  25. alienNumber=2
  26.  
  27.  
  28. # Set up canvases.
  29.  
  30. top=Canvas(root,width=1200,height=50, bg="black")
  31. top.grid(column=0,row=0)
  32.  
  33. playground=Canvas(root,width=1200,height=800,bg='white')
  34. playground.grid(column=0,row=1)
  35.  
  36. userInterface=Canvas(root,width=1200,height=150, bg="black")
  37. userInterface.grid(column=0,row=2)
  38.  
  39. # top Canvas Parameters
  40.  
  41. scoreLabel=Label(top,text="Score: " + str(score), bg="green", fg="white",font=(50))
  42. scoreLabel.place(x=50,y=15)
  43.  
  44. livesLabel=Label(top, text="Lives Left: " + str(lives), bg="red", fg="white",font=(50))
  45. livesLabel.place(x=1040, y=15)
  46.  
  47. # playground Canvas Parameters
  48.  
  49. avoidLine=playground.create_line(0,800,1200,800,fill="red")
  50.  
  51. shipImage=PhotoImage(file="Ship.png")
  52. myShip=playground.create_image(600,530,image=shipImage)
  53.  
  54. alienImage=PhotoImage(file="MyAku2.png")
  55. Alien=playground.create_image(600,100,image=alienImage)
  56.  
  57. Alien2=playground.create_image(400,100,image=alienImage)
  58.  
  59. #   Bottom Canvas Parameters
  60.  
  61. #   Functions programmed here....
  62.  
  63. # Death of the Ship
  64.  
  65. def shipDies():
  66.     global lives
  67.     lives -=1
  68.     livesLabel.config(text="Lives Left: " + str(lives))
  69.     playground(myShip.destroy)
  70.  
  71.  
  72.  
  73.  
  74. #   Detects Collision between the ship and alien
  75.  
  76. def collisionDetection():
  77.     sb=playground.bbox(myShip)
  78.     ab=playground.bbox(Alien)
  79.     # coming from Right Hand Side
  80.     if ab[3]>sb[1] and ab[0]>sb[0]< ab[2]:
  81.         shipDies()
  82.     # coming from left hand side
  83.     if ab[0]<sb[0]<ab[2] and ab[1] <sb[1]<ab[3]:
  84.         shipDies()
  85.     # coming from left below
  86.     if ab[1]<sb[2]<ab[3] and ab[0] <sb[3]<ab[2]:
  87.         shipDies()
  88.     # coming from right below
  89.     if ab[1]<sb[0]<ab[3] and ab[0] <sb[3]<ab[2]:
  90.         shipDies()
  91.  
  92. #   Aliens Move:
  93.  
  94.  
  95.  
  96.  
  97. def AlienMove2():
  98.     global myRandom1
  99.     global myRandom2
  100.     global score
  101.     myMove=random.randint(myRandom1,myRandom2)
  102.     playground.move(Alien2,10,5)
  103.     playground.move(Alien2,-10,5)
  104.     myX=random.randint(-20,20)
  105.     myY=random.randint(5,15)
  106.     playground.move(Alien2,myX,myY)
  107.     MyCoords=playground.bbox(Alien2)
  108.     if MyCoords[1]>800:
  109.         score +=1
  110.         scoreLabel.config(text= "Score: " + str(score))
  111.         playground.coords(Alien2,600,50)
  112.     root.after(myMove,AlienMove2)
  113.  
  114. def AlienMove():
  115.     global myRandom1
  116.     global myRandom2
  117.     global score
  118.     myMove=random.randint(myRandom1,myRandom2)
  119.     playground.move(Alien,10,5)
  120.     playground.move(Alien,-10,5)
  121.     myX=random.randint(-20,20)
  122.     myY=random.randint(5,15)
  123.     playground.move(Alien,myX,myY)
  124.     MyCoords=playground.bbox(Alien)
  125.     if MyCoords[1]>800:
  126.         score +=1
  127.         scoreLabel.config(text= "Score: " + str(score))
  128.         playground.coords(Alien,600,50)
  129.     root.after(myMove,AlienMove)
  130.  
  131.  
  132. #   Key Ship Movements:
  133.  
  134. #   Right
  135.  
  136. def moveRight(event):
  137.  
  138.     randRight=random.randint(1,8)
  139.     playground.move(myShip,10,0)
  140.     playground.move(Alien,randRight,0)
  141.     collisionDetection()
  142.  
  143. #   Left
  144.  
  145. def moveLeft(event):
  146.     playground.move(myShip,-10,0)
  147.     randLeft=random.randint(1,8)
  148.     playground.move(Alien,-randLeft,0)
  149.     collisionDetection()
  150.  
  151. #   Up
  152.  
  153. def moveUp(event):
  154.     playground.move(myShip,0,-10)
  155.     collisionDetection()
  156.  
  157. #   Down
  158.  
  159. def moveDown(event):
  160.     playground.move(myShip,0,10)
  161.     randToward=random.randint(1,5)
  162.     playground.move(Alien,0,randToward)
  163.     collisionDetection()
  164.  
  165.  
  166.  
  167. #   Key Bindings
  168.  
  169. playground.bind_all("<Right>", moveRight)
  170. playground.bind_all("<Left>", moveLeft)
  171. playground.bind_all("<Up>", moveUp)       
  172. playground.bind_all("<Down>", moveDown)
  173.  
  174.  
  175. AlienMove()
  176. timing=random.randint(1000,3000)
  177. root.after(timing, AlienMove2)
  178. root.mainloop()
Attached Images
File Type: png Ship.png (3.6 KB, 53 views)
File Type: png MyAku2.png (2.4 KB, 43 views)
Oct 6 '20 #1
1 3867
Rabbit
12,516 Expert Mod 8TB
It's all in the error message. You're trying to access something called destroy on an object. But that object has nothing called destroy.
Oct 6 '20 #2

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,...
4
by: python newbie | last post by:
Is there anything that would get in the way of me being able to reference an object attribute, from within a list. I have: # one class here class BackupSet: fileGroupList = # ...
0
by: Mike Chirico | last post by:
Hopefully this will help someone... Helpful Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Last Updated: Fri Apr 16 11:47:34 EDT 2004 The latest version of this...
2
by: Looks Like Trent | last post by:
Find a character in a string, at a specified position. How do you do this? Any help will be appreciated....
4
by: Arjen | last post by:
Hi, I have a class with some attributes. For example class person with name as attribute. I have add multiple persons in an arraylist. Now I need a function to get/find a person by the name...
3
by: mike | last post by:
I was calling a new instance of the dll. I'm not used to using dlls, but that was still pretty ignorant of me. Thanks. I really appreciate all the help from Ben,Bryan, and Armin.
3
by: callre | last post by:
when i used javascript onchange() the error is coming "object doesnt support this property" my code is- <script type='text/javascript' language="javascript"> function change() { ...
2
by: BiraRai | last post by:
def getAttributeForProperty(self,rollnumber,attribute): # attribute have the value _ward ''' If year is null then use current year. Returns the value of the attribute for the given roll number...
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?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.