簡體   English   中英

Tkinter 按鈕不出現

[英]Tkinter button does not appear

我正在嘗試為我的 D&D 角色構建一個小型 GUI,但我的第二個攻擊按鈕沒有出現。

試圖讓它盡可能容易閱讀。 這是我第二次嘗試編程,我發現 Tkinter 真的很難使用:(

寫在 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()

您在代碼中有多個root.mainloop() ,它只是暫停代碼繼續執行代碼的 rest。 所以刪除其中一個root.mainloop()並將一個放在代碼的末尾。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM