I made a little python code that makes a ball bounce around the screen. Every time you left click it makes another ball. when you right click it clears the screen but you can't spawn more balls afterward... any help (python, tkinter)
from Tkinter import *
import time
import base_translate as code
info = {}
info["amount"] = code.code(11,62)
class App:
def __init__(self, master):
frame = Frame(master)
frame.pack()
health = Label(master, text="")
health.after(0, lambda:root.destroy())
root = Tk()
d = App(root)
info["x"] = root.winfo_screenwidth()-5
info["y"] = root.winfo_screenheight()-65
root.wait_window()
class App:
def __init__(self, master):
frame = Frame(master)
frame.pack()
def deleteall(event):
info["amount"] = code.code(11,62)
frame.destroy()
start()
def makeball(event):
Bounce(event.x_root, event.y_root,"right","down",info["amount"])
info["amount"] = code.code(code.decode(info["amount"],62)+1,62)
try:
int(info["amount"])
except ValueError:
pass
else:
info["amount"] = code.code(code.decode(info["amount"],62)+10,62)
def Bounce(x, y, movex, movey, ball):
canvas.delete(ball)
canvas.create_oval(x,y, x+25,y+25,fill = "black",outline="white",tag=ball)
if movex == "right":
x = x+1
if x+25 >= info["x"]:
movex = "left"
elif movex == "left":
x = x-1
if x <= 0:
movex = "right"
if movey == "up":
y = y-1
if y <= 0:
movey = "down"
elif movey == "down":
y = y+1
if y+25 >= info["y"]:
movey = "up"
canvas.after(10, lambda:Bounce(x, y, movex, movey, ball))
def start():
frame = Frame(master)
frame.pack()
canvas = Canvas(frame, width = info["x"], height = info["y"], bg="White")
canvas.pack(side=TOP)
canvas.bind("<Button-1>", makeball)
canvas.bind("<Button-3>", deleteall)
canvas = Canvas(frame, width = info["x"], height = info["y"], bg="White")
canvas.pack(side=TOP)
canvas.after(100, lambda:Bounce(0,0,"right","down","a"))
canvas.bind("<Button-1>", makeball)
canvas.bind("<Button-3>", deleteall)
root = Tk()
d = App(root)
root.focus_force()
root.geometry('%dx%d+0+0'%(info["x"],info["y"]))
root.title("BALL!")
root.resizable(FALSE,FALSE)
root.wait_window()
I get the error:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python27\lib\lib-tk\Tkinter.py", line 1410, in __call__
return self.func(*args)
File "C:\Python27\Thropian's games\bouncing ball.py", line 38, in makeball
Bounce(event.x_root, event.y_root,"right","down",info["amount"])
File "C:\Python27\Thropian's games\bouncing ball.py", line 48, in Bounce
canvas.delete(ball)
File "C:\Python27\lib\lib-tk\Tkinter.py", line 2223, in delete
self.tk.call((self._w, 'delete') + args)
TclError: invalid command name ".18725904.18725744"