Tkinter按钮不出现

2024-10-03 17:20:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试为我的D&;但是我的第二个攻击按钮没有出现

尽量使它容易阅读。这是我第二次尝试编程,我发现Tkinter真的很难使用:(

用Python 3编写:

enter image description here

# 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()

Tags: textwithbuttonrootframesidecommandpack
1条回答
网友
1楼 · 发布于 2024-10-03 17:20:34

代码中有多个root.mainloop(),它只是暂停代码继续执行其余代码。因此,删除其中一个root.mainloop(),并将其放在代码末尾

相关问题 更多 >