I don’t know how to go back to the function 'to_be', exit the function.

#!/usr/bin/python3.4 #-*- coding: utf-8 -*- try: # python2 from Tkinter import * except ImportError: # python3 from tkinter import * root = Tk() root.title('MyGui') root.geometry('600x600') def clear(): # очистить фрейм от виджетов if frm.winfo_children(): frm.winfo_children()[0].destroy() def to_be(event): clear() lab = Label(frm, text='What time is it?') clear() lab.place(relx=0.5, rely=0.5, anchor='center') but = Button(frm, text='home') but.place(relx=0.7, rely=0.7, anchor='center') # здесь мне нужно вернуться в начало программы but.bind('<Button-1>', 'по нажатию кнопки нужно выйти из функции') frm = Frame(root, width=500, height=500, bg='#008B8B') lab = Label(frm, text='Глагол to be', bg='#008B8B', font='Inconsolata 13') lab.place(x=250, y=10, anchor='center') but = Button(frm, text='Ok', bg='blue') but.place(x=200, y=20, width=100) frm.pack() but.bind('<Button-1>', to_be) root.focus_force() root.mainloop() 
  • The program to_be() function after the execution of but.bind(...) . Write what exactly you want to do, what does “go back” mean? - insolor
  • I need to return to the beginning where there is an inscription 'Verb to_be'. - Mike Ru
  • It seems that you just need to bring the code, the execution of which you need to "repeat" in a separate function, and bind it to a button click. - insolor
  • Aha I thought so. Thanks you! - Mike Ru
  • if it works out, issue a response. - insolor

1 answer 1

I decided myself, complete nonsense, but it works. I designed the main function 'basic' (in my case this is the main window of my program. I quote the code!

 #!/usr/bin/python3.4 #-*- coding: utf-8 -*- try: # python2 from Tkinter import * except ImportError: # python3 from tkinter import * root = Tk() root.title('Trainer') root.geometry('600x600') def clear(): if frm.winfo_children(): frm.winfo_children()[0].destroy() def to_be(event): clear() lab = Label(frm, text='What time is it?') lab.place(relx=0.5, rely=0.5, anchor='center') clear() but = Button(frm, text='home') but.place(relx=0.7, rely=0.7, anchor='center') but.bind('<Button-1>', basic) frm = Frame(root, width=500, height=500, bg='#008B8B') def basic(*event): clear() clear() lab = Label(frm, text='Глагол to be', bg='#008B8B', font='Inconsolata 13') lab.place(x=250, y=10, anchor='center') but = Button(frm, text='Ok', bg='blue') but.place(x=200, y=20, width=100) frm.pack() but.bind('<Button-1>', to_be) root.focus_force() root.mainloop() basic() 
  • one
    def to_be (event): return - Alexander