Hello everyone, I am writing a small program with an interface on Tkinter and I am faced with difficulty.
Conventionally, when a function is called (a click on the values in Frame A), the conditional parameters are passed to the next frame (Frame B) and visualized, each time being updated in the Entry widget.
Depending on the value of the parameter passed (for example, "OMS"), you must provide the option to perform some other operation (function), and the button ("Do Smt") is drawn for this. But after selecting the next value, the button remains "hang" in frame B.
Tell me whether it is possible to somehow implement the check in the user_choice function of the presence of a button in Frame B and delete it. I understand that before each user_choice () call, I can delete all Frame B widgets and redraw them, but this solution seems like a crutch, I want to find a more delicate solution.
Sample code:
import tkinter as tk from tkinter import ttk class main_interface(): def __init__(self): self.window = tk.Tk() self.window.geometry("20x450") self.create_widgets() def create_widgets(self): self.window['padx'] = 10 self.window['pady'] = 10 entry = ttk.Entry(self.window, width=30) entry.grid(row=1, column=1, sticky=tk.W, pady=3) frame1 = ttk.LabelFrame(self.window, text="Frame A", relief=tk.RIDGE, width=200, height=200) frame1.grid(row=1, column=1, sticky=tk.E + tk.W + tk.N + tk.S) frame2 = ttk.LabelFrame(self.window, text="Frame B", relief=tk.RIDGE, width=200, height=200) frame2.grid(row=1, column=2, sticky=tk.E + tk.W + tk.N + tk.S) entry = ttk.Entry(frame2, width=30) entry.grid(row=1, column=1, sticky=tk.W, pady=3) request = {"NSK": "9383XXXX", "OMS": "9381XXXX", "TMN": "9345XXXX", "KZN": "9843XXXX", "NNV": "9831XXXX"} for row, (key, value) in enumerate(request.items()): formated_text = " {} - {}".format(key, value) found_result_label = ttk.Label(frame1, text=formated_text) selected_string = key, value found_result_label.bind("<Button-1>", func=lambda event, text=selected_string: user_choice(text)) found_result_label.grid(row=row, column=1, sticky=tk.W) def user_choice(text): entry.delete(0, "end") entry.insert(0, text) if text[0] == "OMS": button = ttk.Button(frame2, text="Do Smt", command=lambda: fx()) button.grid(row=2, column=1, sticky=tk.W) def fx(): pass program = main_interface() program.window.mainloop()