Transition of screens - Tkinter

0

Let's say there's a three-button screen (Tkinter), each calling another screen when clicked. How to switch between these screens without getting that screen aspect destroyed and a new one appearing? The idea is that it looks like the contents of one screen have been replaced by another and not that you close the window and open another.

    
asked by anonymous 01.08.2018 / 05:44

2 answers

2

Just put your components in separate frames, then you can toggle them:

import functools
import tkinter as t

class Tela(t.Frame):
    def __init__(self, parent, nome):
        t.Frame.__init__(self, parent)
        self.nome = nome
        t.Label(self, text='Voce esta na ' + self.nome).pack()

class Menu(t.Frame):
    def __init__(self, parent, *subtelas):
        t.Frame.__init__(self, parent)
        self.current_frame = self
        for subtela in subtelas:
            t.Button(subtela, text='Voltar',
                command=functools.partial(self.muda_tela, self)).pack()
            t.Button(self, text=subtela.nome, 
                command=functools.partial(self.muda_tela, subtela)).pack()

    def muda_tela(self, qual):
        self.current_frame.pack_forget()
        qual.pack()
        self.current_frame = qual

if __name__ == '__main__':
    root = t.Tk()
    root.resizable(0, 0)
    t1 = Tela(root, 'Primeira tela')
    t2 = Tela(root, 'Segunda tela')
    t3 = Tela(root, 'Terceira tela')    

    m = Menu(root, t1, t2, t3)
    m.pack()

    root.mainloop()
    
01.08.2018 / 17:40
-1

I wanted it when I pressed the button, another window would open according to the messages. ex: access released, the window would abir.access denied the window did not open, anyone know how to do it ?.

from tkinter import*
from tkinter import messagebox


janela = Tk()


def entra():
log = str(et1.get())
senha = str(et2.get()) 
if log == '123' and senha == '123' :
     messagebox.showinfo(title = ' login' , message  = 'acesso liberado')

root = Tk()
root.title('Menu')  
root.mainloop
else:
    messagebox.showinfo(title = ' login' , message  = 'acesso negado')

root = Tk()
root.title('Menu')  
root.mainloop





lb_titulo= Label (janela, text= ' Tela de login', font= ["Times New Roman", 30]  )
lb_titulo.pack(side = TOP )

et1= Entry(janela)
et1.place(x= 80 , y= 100 )

et2= Entry(janela )
et2.place( x= 80 , y= 140 )

lb_log= Label (janela, text= '  login:' )
lb_log.place(x= 30 , y= 100 )

lb_senha= Label (janela, text= ' senha: ')
lb_senha.place( x= 30 , y= 140 )

bt_entra= Button (janela, text = "entra" ,width = 15 ,command = entra )
bt_entra.place( x= 150 , y= 240 )






janela.title('Tela de login')
janela.geometry("400x350+300+300")
# não deixa redimecionar a tela resizable(False,False)#
janela.resizable(False,False)


janela.mainloop()
    
05.01.2019 / 20:28