Как мне уничтожить фрейм, созданный в классе, который будет использоваться в основном классе?
По сути, у меня есть графический интерфейс основного класса, который я создаю окно ткинтера. Затем у меня есть еще один класс под ним, class Initialise(ttk.Frame), который создает виджеты. Но на основании нажатой кнопки виджета я хочу уничтожить весь фрейм, как мне это сделать?
вот main.py
class GUI(Tk):
def __init__(self, title, size, color):
super().__init__()
# Window setup
self.title(title)
self.config(bg=color)
self.geometry(f"{size[0]}x{size[1]}")
self.minsize(size[0], size[1])
# Frame BG color
ttk.Style().configure("BG.TFrame", background=THEME_COLOR)
# Create Widget
self.start_app()
# Run GUI
self.mainloop()
def start_app(self):
self.intitlise = Initialise(self)
# In this method I want to destroy the frame which is made in start_app()
def destroy_initilisor(self):
self.intitlise.destroy()
self.intitlise = None
Вот виджет, созданный в этом классе
class Initialise(ttk.Frame):
def __init__(self, parent):
super().__init__(parent, style="BG.TFrame")
self.destroy_this = False
self.next_question = False
self.display_list = False
ttk.Style().configure("Button.TButton", font=FONT_BOLD)
self.create_widgets()
self.place(x=0, y=0, relwidth=1, relheight=1)
def create_widgets(self):
# Setting column and row grid configurations
self.columnconfigure(0, weight=1, uniform="a")
self.columnconfigure(1, weight=4, uniform="a")
self.columnconfigure(2, weight=4, uniform="a")
self.columnconfigure(3, weight=1, uniform="a")
self.rowconfigure((0,1,2,), weight=1, uniform="a")
# creating first button
self.new_button = ttk.Button(self, text="Save a new Athlete", style="Button.TButton", command=self.question)
self.new_button.grid(column=1, row=1, padx=5, sticky="we")
# creating second button
self.display_all_athletes = ttk.Button(self, text="Saved Athletes", style="Button.TButton", command=self.show_athletes)
self.display_all_athletes.grid(column=2, row=1, padx=5, sticky="we")
# if button 1 is pressed aim is to destroy it and the other button in the parent class GUI
def question(self):
self.next_question = True
self.display_list = False
# calling the destroyer
self.destroy_widget()
# if button 2 is pressed aim is to destroy it and the other button in the parent class GUI
def show_athletes(self):
self.display_list = True
self.next_question = False
self.destroy_widget()
# I am setting self.destroy_this = True because in the parent I want to destroy it
def destroy_widget(self):
print("IS IT HERE?!")
self.destroy_this = True
Как инициализировать приложение с помощью кнопки кода
if __name__ == "__main__":
root = GUI("Golden Gloves Program Training Fee Calculator.", (600,600), THEME_COLOR)
# I think I am tracing it here?
if root.intitlise.destroy_this:
print("IS IT DESTROYING?!")
root.destroy_initilisor()
Подробнее здесь: https://stackoverflow.com/questions/786 ... sed-in-the
Tkinter, как уничтожить Frame, созданный из другого класса и используемый в основном классе? ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
GDALWarpRegionToBuffer и мозаика, когда Dst Frame не содержится строго в Src Frame
Anonymous » » в форуме C++ - 0 Ответы
- 89 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Ошибка с использованием @indie.param в инди: «Параметр, не используемый в основном»
Anonymous » » в форуме Python - 0 Ответы
- 5 Просмотры
-
Последнее сообщение Anonymous
-