mardi 14 octobre 2014

delete an instance of the object PYTHON


Vote count:

0




I'm trying to understand the class notion in Python and having decided to do a little exercice I found myself facing a problem.


What I'm trying to do is to create a circle (on a mouse click) and then I expect the program to delete the circle in 3 seconds.


...I admit it's a useless task, absolutely, but I'm doing this because I encountered a problem whick means that I don't entirely understand the concept of classes and objects.


My code:


from tkinter import *


import time


class Application:



def __init__(self):
self.fen = Tk()
self.fen.title('Rom-rom-roooooom')
self.butt1 = Button(self.fen, text = ' Quit ', command = self.fen.quit)
self.can1 = Canvas(self.fen, width = 300, height = 300, bg = 'ivory')
self.can1.grid(row = 1)
self.butt1.grid(row = 2)
self.fen.bind("<Button-1>", self.create_obj)
self.fen.mainloop()
def create_obj(self, event):
d = self.can1.create_oval(150,150, 170, 170, fill='red', width = 2)
time.sleep(3)
d.kill()


appp = Application()


and I get this error: AttributeError: 'int' object has no attribute 'kill'


I expect the variable 'd' to be an instance of the object, but I'm wrong, I guess. What did I do wrong?


Thanks in advance!



asked 47 secs ago







delete an instance of the object PYTHON

Aucun commentaire:

Enregistrer un commentaire