简体   繁体   English

Tkinter 按钮不出现

[英]Tkinter button does not appear

I am trying to build a small GUI for my D&D character but my second attack button does not appear.我正在尝试为我的 D&D 角色构建一个小型 GUI,但我的第二个攻击按钮没有出现。

Tried to make it read as easy as possible.试图让它尽可能容易阅读。 Its my second try on programming, I find the Tkinter really difficult to work with:(这是我第二次尝试编程,我发现 Tkinter 真的很难使用:(

Written in Python 3:写在 Python 3 中:

在此处输入图像描述

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

You have multiple root.mainloop() in the code, it just pauses the code from continuing the execution of rest of the code.您在代码中有多个root.mainloop() ,它只是暂停代码继续执行代码的 rest。 So remove one of the root.mainloop() and place one at the end of the code.所以删除其中一个root.mainloop()并将一个放在代码的末尾。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM