大家好!我没有调用该函数attack_zone()
。我的错误是什么?
from tkinter import *
from tkinter import messagebox
from threading import Thread
from playsound import playsound
kill_boss=False
robot_health = 100
def attack():
global robot_health,kill_boss
if robot_health==0:
kill_boss=True
else:
robot_health-=1
kill = False
fight = Tk()
fight['bg']='black'
fight.geometry("400x400")
fight.title('Битва')
w = 500
h=500
Canvas = Canvas(bg='black')
Canvas.pack()
def kot(a):
messagebox.showinfo('Заголовок',a)
global a1
global a2
global b1
global b2
global c1
global c2
global d1
global d2
a1= 15
a2=15
d1=25
d2=25
c1=a1
c2=d2
b1=d1
b2=d1
player = Canvas.create_rectangle(a1,a2,d1,d2,fill='red')
Button(fight,bg='red',comand=attack()).pack()
def down():
global a1
global a2
global b1
global b2
global c1
global c2
global d1
global d2
Canvas.move(player,0,10)
d2=+1
c2=+1
def up():
global a1
global a2
global b1
global b2
global c1
global c2
global d1
global d2
Canvas.move(player,0,-10)
d2=-10
c2-=10
def left():
global a1
global a2
global b1
global b2
global c1
global c2
global d1
global d2
Canvas.move(player,-10,0)
c1=-10
d1-=10
def right():
global a1
global a2
global b1
global b2
global c1
global c2
global d1
global d2
Canvas.move(player,10,0)
c1=+10
d1=+10
global x1
global x2
global y1
global y2
x1=0
x2=10
y1=1000
y2=100
def luch():
Canvas.create_rectangle(x1,x2,y1,y2,fill='white')
luch()
photo = PhotoImage(file = "1 враг.gif")
label = Label(image = photo).pack()
fight.mainloop()
w.bind("<Up>", lambda event:up)
w.bind("<Left>", lambda event:left)
w.bind("<Right>", lambda event:right)
w.bind("<Down>", lambda event:down)
def attack_zone():
kot('kjhkjkl')
global a1
global a2
global b1
global b2
global c1
global c2
global d1
global d2
global x1
global x2
global y1
global y2
kot('kjhkjkl')
gorizontal = False
vertical = False
if a2<x2 and d2>y2:
gorizontal = True
if a1<x1 and d1>y1:
vertical = True
if gorizontal and vertical:
kot("game_over")
attack_zone()
#请勿抄袭代码
我认为这会奏效。将主循环移至末尾。在主循环后关闭窗口之前的功能将不起作用