Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_delete_obj.py
- from Tkinter import *
- import random
- import time
- root = Tk()
- root.resizable(0,0)
- root.wm_attributes("-topmost", 1)
- canvas = Canvas(root, width=500, height=400, bd=0, highlightthickness=0)
- canvas.pack()
- class Ball:
- def __init__(self, canvas, color):
- self.canvas = canvas
- self.id = canvas.create_oval(10, 10, 25, 25, fill=color)
- self.canvas.move(self.id, 245, 100)
- self.canvas.bind("<Button-1>", self.canvas_onclick)
- self.text_id = self.canvas.create_text(300, 200, anchor='se')
- self.canvas.itemconfig(self.text_id, text='Click Anywhere On Canvas')
- def canvas_onclick(self, event):
- x,y = event.x, event.y
- self.canvas.itemconfig(
- self.text_id,
- text="You clicked at ({}, {})".format(x, y)
- )
- self.canvas.delete(self.id)
- self.id = canvas.create_oval(x, y, x+15, y+15, fill="red")
- def draw(self):
- self.canvas.move(self.id, 0, -1)
- self.canvas.after(50, self.draw)
- ball = Ball(canvas, "red")
- ball.draw()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement