不多说了上代码
#血条测试实验
import tkinter as tk
win = tk.Tk()
win.title('血条测试')
win.geometry('300x300')
hp = 80
label = tk.Label(bg = "red",width = 80)
label.place(relx = 0,rely = 0)
label1 = tk.Label(bg = "blue",width = hp)
label1.place(relx = 0,rely = 0)
def hit():
global hp
hp -= 10
print(hp)
if hp < 0:
print("Game Over")
label1.config(width = hp)
def hui():
global hp
if hp >= 80:
pass
else:
hp += 10
print(hp)
if hp < 0:
print("Game Over")
label1.config(bg = "red")
win.update()
label1.config(width = hp)
b = tk.Button(text="减血",command = hit)
b.place(relx = 0,rely = 0.24)
b2 = tk.Button(text="加血",command = hui)
b2.place(relx = 0.32,rely = 0.24)
win.mainloop()