I have an issue with restarting my game called "Bounce"
You may have to reset all the variables to initial state to restart.I have added a restart method which first stops the paddle, destroys the ball, resets the score and initializes the ball to the start position. Also find corresponding methods in the classes.
from tkinter import *import randomimport timeclass Bal: def __init__(self, canvas, paddle, score, color): self.canvas = canvas self.paddle = paddle self.score = score self.id = canvas.create_oval(10, 10, 25, 25, fill=color) self.canvas.move(self.id, 200, 100) starts = [-3, -2, -1, 1, 2, 3] random.shuffle(starts) self.x = starts[0] self.y = -3 self.canvas_height = self.canvas.winfo_height() self.canvas_width = self.canvas.winfo_width() self.hit_bottom = False def restart(self, canvas, paddle, score, color): self.__init__(canvas, paddle, score, color) def hit_paddle(self, pos): paddle_pos = self.canvas.coords(self.paddle.id) if pos[2] >= paddle_pos[0] and pos[0] <= paddle_pos[2]: if pos[3] >= paddle_pos[1] and pos[3] <= paddle_pos[3]: self.score.hit() return True return False def destroy(self): self.canvas.delete(self.id) def draw(self): self.canvas.move(self.id, self.x, self.y) pos = self.canvas.coords(self.id) if pos [1] <= 0: self.y = 3 if pos [3] >= self.canvas_height: self.hit_bottom = True if self.hit_paddle(pos) == True: self.y = -3 if pos [0] <= 0: self.x = 3 if pos [2] >= self.canvas_width: self.x = -3class paddle: def __init__(self, canvas, color): self.canvas = canvas self.id = canvas.create_rectangle(0, 0, 100, 10, fill=color) self.canvas.move(self.id, 200, 300) self.started = False self.x = 0 self.canvas_width = self.canvas.winfo_width() self.canvas.bind_all('<KeyPress-Left>', self.turn_left) self.canvas.bind_all('<KeyPress-Right>', self.turn_right) self.canvas.bind_all('<Button-1>', self.start_game) def draw(self): self.canvas.move(self.id, self.x, 0) pos = self.canvas.coords(self.id) if pos[0] <= 0: self.x = 0 elif pos[2] >= self.canvas_width: self.x = 0 def turn_left(self, evt): self.x = -3 def start_game(self, evt): self.started = True def stop(self): self.started = False def turn_right(self, evt): self.x = 3class score: def __init__(self, canvas, color): self.score = 0 self.canvas = canvas self.id = canvas.create_text(450,20, text=self.score,font=("Times", 20), fill=color) def hit(self): self.score += 1 self.canvas.itemconfig(self.id, text=self.score) def reset_score(self): self.score = 0tk = Tk()tk.title("bouncespel made by Robel Tewolde")tk.resizable(0,0)tk.wm_attributes("-topmost", 1)canvas = Canvas(tk, width=500, height=400, bd=0, highlightthickness=0)canvas.configure(background='black')canvas.pack()tk.update()score = score(canvas, 'red') paddle = paddle(canvas, 'White')bal = Bal(canvas, paddle, score,'red')def restart(): bal.destroy() paddle.stop() score.reset_score() bal.restart(canvas, paddle, score, 'red')spel_over = canvas.create_text(400, 200,font="Times", text='HET SPEL IS AFGELOPEN', state='hidden')def quit(event): print("Double Click, so let's stop") import sys; sys.exit() while 1: if bal.hit_bottom == False and paddle.started == True: bal.draw() paddle.draw() if bal.hit_bottom == True: restart() canvas.itemconfig(spel_over, state='normal') tk.update_idletasks() tk.update() time.sleep(0.01)