【发布时间】:2022-11-01 21:45:50
【问题描述】:
from random import randrange
class App5(tk.Toplevel):
def __init__(self, title: str):
super().__init__()
self.title(title)
self.style = ttk.Style(self)
self.style.theme_use("classic")
self.geometry("490x250")
self.tres_label = ttk.Label(
self,
text="Oh yeah, also while you were doing that, I enrolled you into a tournament. \nHave fun........what? Why did I sign you up for a tournament you didn't ask for? \nTo increase the total run time on this project.",
)
self.tres_label.grid(row=0, column=0, padx=5, pady=5)
self.rng_button = ttk.Button(self, text="Click Me", command=self.rng)
self.rng_button.grid(row=2, column=0, padx=5, pady=5)
def rng(self):
class Character:
def __init__(self, name: str, hp: int, damage: int):
self.name = name
self.hp = hp
self.damage = damage
Goodguy = Character("Goodguy", 300, 75)
Badguy = Character("Badguy", 375, 25)
score = 70
num = randrange(0, 100)
G = Goodguy.hp - Badguy.damage
B = Badguy.hp - Goodguy.damage
if num >= score:
Goodguy.hp - Badguy.damage
Badguy.hp - Goodguy.damage
self.good = ttk.Label(self, text="Goodguy Hp:" + G)
self.good.grid(row=3, column=3)
self.bad = ttk.Label(self, text="BadGuy Hp:" + B)
self.bad.grid(row=3, column=6)
B = B - Goodguy.damage
G = G - Badguy.damage
else:
Goodguy.hp - Badguy.damage
self.good = ttk.Label(self, text="Goodguy Hp:" + G)
self.good.grid(row=3, column=3)
self.bad = ttk.Label(self, text="BadGuy Hp:" + B)
self.bad.grid(row=3, column=6)
B = B - Goodguy.damage
G = G - Badguy.damage
当 Tkinter 窗口中出现连接错误时,我无法解决它。我尝试使用多种方法,但是它们对我正在尝试做的事情并不奏效。我正在努力做到这一点,点击 Tkinter 按钮,它会随机选择 0 到 100 之间的值。如果随机值小于或等于 70,则“好人”和“坏人” “会降低他们的健康水平。但如果大于 70,Good guy 只会受到伤害。然后它将他们的新马力打印到窗口中。
【问题讨论】: