Valaki segítene? Az alábbi scriptben hibás a következő sor: abl1. after (50, move_ball) A nyelv Python.
from Tkinter import *
from random import randrange
def move_ball():
global flag, x, y, moving
if moving == True:
move_ball_right_down()
if moving == False:
move_ball_left_up()
if x <= 20 or y <= 20:
moving = True
if x >= 480 or y >= 480:
moving = False
if flag >0:
abl1.after(50, move_ball)
def move_ball_right_down():
global x, y
x, y = randrange(0, 400), randrange(0, 400)
can.coords(ball, x-r, y-r, x+r, y+r)
def move_ball_left_up():
global x, y
x, y = randrange(400, 0), randrange(400, 0)
can.coords(ball, x-r, y-r, x+r, y+r)
def click_ball(event):
global x, y, points, ball, r, flag
if flag == 1 and ((event.x-x)**2 + (event.y-y)**2) <= r**2:
points = points + 1
lab2.configure(text = "Points: " + str(points))
r = r - 1
can.coords(ball, x-r, y-r, x+r, y+r)
pal = ["red", "green", "white", "blue", "black", "yellow", "magenta"]
m = randrange(7)
color = pal[m]
can.itemconfig(ball, fill = color)
if points == 15:
lab2.configure(text = "Points: " + str(points) + " - You won!", fg = "green")
flag = 0
def start():
global flag
if flag == 0 and points < 15:
flag = 1
move_ball()
def pause():
global flag
flag = 0
def restart():
global points, r, x, y, flag, dx
x, y = 250, 250
r = 20
points = 0
moving = True
can.coords(ball, x-r, y-r, x+r, y+r)
can.itemconfig(ball, fill = "red")
lab2.configure(text = "Points: " + str(points))
if flag == 0:
flag = 1
move_ball()
x, y = 250, 250
r = 20
flag = 0
moving = True
points = 0
abl1 = Tk()
abl1.title("Clicky game")
can = Canvas(abl1, height = 500, width = 500, bg = "light grey")
can.grid(row = 3, column = 1, columnspan = 3, sticky = N)
can.bind("<Button-1>", click_ball)
lab = Label(abl1, text = "Click on the 'Start' button, then catch the ball!")
lab.grid(row = 1, column = 2, sticky = N, pady = 2)
lab2 = Label(abl1, text = "Points: 0", fg = "red")
lab2.grid(row = 2, column = 2, sticky = N, pady = 2)
ball = can.create_oval(x-r, y-r, x+r, y+r, fill = "red")
but1 = Button(abl1, text = "Quit", command = abl1.destroy)
but1.grid(row = 4, column = 3, sticky = E, padx = 5, pady = 5)
but2 = Button(abl1, text = "Start", command = start)
but2.grid(row = 4, column = 1, sticky = W, padx = 10, pady = 5)
but3 = Button(abl1, text = "Pause", command = pause)
but3.grid(row = 4, column = 1, sticky = E, padx = 10, pady = 5)
but4 = Button(abl1, text = "Restart", command = restart)
but4.grid(row = 4, column = 2, sticky = W, padx = 10, pady = 5)
abl1.mainloop()
Kapcsolódó kérdések:
Minden jog fenntartva © 2024, www.gyakorikerdesek.hu
GYIK | Szabályzat | Jogi nyilatkozat | Adatvédelem | Cookie beállítások | WebMinute Kft. | Facebook | Kapcsolat: info(kukac)gyakorikerdesek.hu
Ha kifogással szeretne élni valamely tartalommal kapcsolatban, kérjük jelezze e-mailes elérhetőségünkön!