Я создал рабочую версию из вашего кода. Вы можете найти мои выводы в приведенном ниже коде в качестве комментариев.
Я не совсем уверен, что вы ожидаете от своего кода. Теперь кнопки «Quit» и «Loot» видны во фрейме, и если вы нажмете кнопку «Quit», программа завершится (кнопка «Loot» ничего не делает).
Код:
from tkinter import Frame, BOTH, Button, Tk
class Menu(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.master = master
self.init_menu()
# You have to call the "client_exit" method to rendering the "Loot" button to Frame.
self.client_exit()
def init_menu(self):
self.master.title("DUNGEON MENU")
self.pack(expand=True, fill=BOTH)
# Destroy the master if you click to the "Quit" button.
quitB = Button(self, text="Quit", fg="red", command=lambda: self.master.destroy())
quitB.grid(row=0, column=0, padx=120)
def client_exit(self):
# exit() # This exit is not needed because it breaks the program running.
# You can define the call-back of button in "command" parameter of Button object.
lootB = Button(self, text="Loot", command=None)
lootB.grid(row=1, column=0, padx=120)
root = Tk()
root.geometry("300x300")
app = Menu(root)
root.mainloop()
# button.pack() # It does not have effect. You cannot define widgets after "mainloop"
Выход:
>>> python3 test.py