Tkinter 按钮不出现
Tkinter button does not appear
我正在尝试为我的 D&D 角色构建一个小型 GUI,但我的第二个攻击按钮没有出现。
试图让它尽可能容易阅读。这是我第二次尝试编程,我发现 Tkinter 真的很难用:(
写在Python3:
# Tkinter_buildframe #
root = tk.Tk()
frame = tk.Frame(root)
frame.pack( side = TOP )
frame.pack()
root.geometry("300x200")
# This is the charicter stats #
w = Label(root, text="""
charisma modifier = 4
spellcast attack_bonus = 7
""", font="12")
w.pack()
# Quit_button #
button = tk.Button(frame,
text="QUIT",
fg="red",
command=quit)
button.pack(side=tk.BOTTOM)
# Attack1 eldritch_blast_with_hex #
slogan = tk.Button(frame,
text="Eldritch Blast with Hex",
command=eldritch_blast_with_hex)
slogan.pack(side=tk.LEFT)
root.mainloop()
def popupmsg(msg):
popup = tk.Tk()
popup.wm_title("Eldritch Blast with Hex")
label = ttk.Label(popup, text=msg, font=NORM_FONT)
label.pack(side="top", fill="x", pady=10)
B1 = ttk.Button(popup, text="Okay", command = popup.destroy)
B1.pack()
popup.mainloop()
# Attack2 eldritch_blast_without_hex#
slogan = tk.Button(frame,
text="Eldritch Blast without Hex",
command=eldritch_blast_without_hex)
slogan.pack(side=tk.LEFT)
root.mainloop()
def popupmsg(msg):
popup = tk.Tk()
popup.wm_title("Eldritch Blast without Hex")
label = ttk.Label(popup, text=msg, font=NORM_FONT)
label.pack(side="top", fill="x", pady=10)
B1 = ttk.Button(popup, text="Okay", command = popup.destroy)
B1.pack()
您的代码中有多个 root.mainloop()
,它只是暂停代码以继续执行其余代码。因此,删除其中一个 root.mainloop()
并在代码末尾放置一个。
我正在尝试为我的 D&D 角色构建一个小型 GUI,但我的第二个攻击按钮没有出现。
试图让它尽可能容易阅读。这是我第二次尝试编程,我发现 Tkinter 真的很难用:(
写在Python3:
# Tkinter_buildframe #
root = tk.Tk()
frame = tk.Frame(root)
frame.pack( side = TOP )
frame.pack()
root.geometry("300x200")
# This is the charicter stats #
w = Label(root, text="""
charisma modifier = 4
spellcast attack_bonus = 7
""", font="12")
w.pack()
# Quit_button #
button = tk.Button(frame,
text="QUIT",
fg="red",
command=quit)
button.pack(side=tk.BOTTOM)
# Attack1 eldritch_blast_with_hex #
slogan = tk.Button(frame,
text="Eldritch Blast with Hex",
command=eldritch_blast_with_hex)
slogan.pack(side=tk.LEFT)
root.mainloop()
def popupmsg(msg):
popup = tk.Tk()
popup.wm_title("Eldritch Blast with Hex")
label = ttk.Label(popup, text=msg, font=NORM_FONT)
label.pack(side="top", fill="x", pady=10)
B1 = ttk.Button(popup, text="Okay", command = popup.destroy)
B1.pack()
popup.mainloop()
# Attack2 eldritch_blast_without_hex#
slogan = tk.Button(frame,
text="Eldritch Blast without Hex",
command=eldritch_blast_without_hex)
slogan.pack(side=tk.LEFT)
root.mainloop()
def popupmsg(msg):
popup = tk.Tk()
popup.wm_title("Eldritch Blast without Hex")
label = ttk.Label(popup, text=msg, font=NORM_FONT)
label.pack(side="top", fill="x", pady=10)
B1 = ttk.Button(popup, text="Okay", command = popup.destroy)
B1.pack()
您的代码中有多个 root.mainloop()
,它只是暂停代码以继续执行其余代码。因此,删除其中一个 root.mainloop()
并在代码末尾放置一个。