Пример кода не дает подробного указания, ссылка на диск Google не работает.
Так что в основном это всего лишь предположение, я предполагаю, что вы хотите скрыть / показать Toplevel
.
По какой-то причине работает:
import tkinter as tk
def clicked_on_text_editor(event = "<Button-1>"):
Text1.withdraw()
def clicked_again(event = "<Button-1>"):
Text1.deiconify()
Port.bind("<Button-1>", clicked_on_text_editor)
Port.bind("<Button-1>", clicked_again)
root = tk.Tk()
Text1 = tk.Toplevel()
Port = tk.Label(root, text = "Total Guess")
Port.pack(padx = 50, pady = 20)
Port.bind("<Button-1>", clicked_on_text_editor)
root.mainloop()
Я бы не стал так делать, я бы, наверное, сделал что-то вроде этого:
import tkinter as tk
def clicked_on_text_editor(e):
if e.widget.toggle:
Text1.withdraw()
else:
Text1.deiconify()
e.widget.toggle = not e.widget.toggle # Changes True to False, False to True.
root = tk.Tk()
Text1 = tk.Toplevel()
Port = tk.Label(root, text = "Total Guess")
Port.toggle = True # Assign a toggle attribute, can be anything not currently an attribute.
Port.pack(padx = 50, pady = 20)
Port.bind("<Button-1>", clicked_on_text_editor)
root.mainloop()