Call another screen in Kinter

Asked

Viewed 59 times

-1

I’m trying to create a main screen with two buttons to call the screens "Stock and "Customers", but instead of closing and opening, it adds on the same screen.

from clientes import Clientes
from tkinter import *


class Application:
    def __init__(self, master=None):

        self.fonte = ("Verdana", "8")
        root.iconbitmap('ico.ico')
        root.title("Cadastro de clientes: ")
        root.geometry("300x300")
        self.container1 = Frame(master)
        self.container1["pady"] = 10
        self.container1.pack()
        self.container2 = Frame(master)
        self.container2["padx"] = 20
        self.container2["pady"] = 5
        self.container2.pack()

        self.titulo = Label(self.container1, text="Informe os dados :")
        self.titulo["font"] = ("Calibri", "9", "bold")
        self.titulo.pack()

        self.btnCliente = Button(self.container2, text="Clientes", command=lambda: self.Clientes(),
                                 font=self.fonte, width=10)
        self.btnCliente.pack(side=RIGHT)

        self.btnEstoque = Button(self.container2, text="Estoque", command=lambda: self.Estoque(),
                                 font=self.fonte, width=10)
        self.btnEstoque.pack(side=RIGHT)


    def Clientes(self, master=None):
        self.fonte = ("Verdana", "8")
        root.iconbitmap('ico.ico')
        root.title("Cadastro de clientes: ")
        root.geometry("300x300")
        self.container1 = Frame(master)
        self.container1["pady"] = 10
        self.container1.pack()
        self.container2 = Frame(master)
        self.container2["padx"] = 20
        self.container2["pady"] = 5
        self.container2.pack()
        self.container3 = Frame(master)
        self.container3["padx"] = 20
        self.container3["pady"] = 5
        self.container3.pack()
        self.container4 = Frame(master)
        self.container4["padx"] = 20
        self.container4["pady"] = 5
        self.container4.pack()
        self.container5 = Frame(master)
        self.container5["padx"] = 20
        self.container5["pady"] = 5
        self.container5.pack()
        self.container6 = Frame(master)
        self.container6["padx"] = 20
        self.container6["pady"] = 5
        self.container6.pack()
        self.container7 = Frame(master)
        self.container7["padx"] = 20
        self.container7["pady"] = 5
        self.container7.pack()
        self.container8 = Frame(master)
        self.container8["padx"] = 20
        self.container8["pady"] = 10
        self.container8.pack()
        self.container9 = Frame(master)
        self.container9["pady"] = 15
        self.container9.pack()

        self.titulo = Label(self.container1, text="Informe os dados :")
        self.titulo["font"] = ("Calibri", "9", "bold")
        self.titulo.pack()

        self.txtcpf = Label(self.container2,
                            text="Cpf:", font=self.fonte, width=10)
        self.txtcpf.pack(side=LEFT)

        self.txtcpf = Entry(self.container2)
        self.txtcpf["width"] = 15
        self.txtcpf["font"] = self.fonte

        self.txtcpf.pack(side=LEFT)

        self.btnBuscar = Button(self.container2, text="Buscar",
                                font=self.fonte, width=10)
        self.btnBuscar["command"] = self.buscarCliente
        self.btnBuscar.pack(side=RIGHT)

        self.lblnome = Label(self.container3, text="Nome:",
                             font=self.fonte, width=10)
        self.lblnome.pack(side=LEFT)

        self.txtnome = Entry(self.container3)
        self.txtnome["width"] = 25
        self.txtnome["font"] = self.fonte
        self.txtnome.pack(side=LEFT)

        self.lbltel = Label(self.container5, text="Telefone: ",
                            font=self.fonte, width=10)
        self.lbltel.pack(side=LEFT)

        self.txttel = Entry(self.container5)
        self.txttel["width"] = 25
        self.txttel["font"] = self.fonte
        self.txttel.pack(side=LEFT)

        self.btnInsert = Button(self.container8, text="Inserir",
                                font=self.fonte, width=10)
        self.btnInsert["command"] = self.inserirCliente
        self.btnInsert.pack(side=RIGHT)

        self.btnAlterar = Button(self.container8, text="Alterar",
                                 font=self.fonte, width=12)
        self.btnAlterar["command"] = self.alterarCliente
        self.btnAlterar.pack(side=LEFT)

        self.btnExcluir = Button(self.container8, text="Excluir",
                                 font=self.fonte, width=12)
        self.btnExcluir["command"] = self.excluirCliente
        self.btnExcluir.pack(side=LEFT)

        self.lblmsg = Label(self.container9, text="")
        self.lblmsg["font"] = ("Verdana", "9", "italic")
        self.lblmsg.pack()

    def inserirCliente(self):
        cli = Clientes()

        cli.cpf = self.txtcpf.get()
        cli.nome = self.txtnome.get()
        cli.telefone = self.txttel.get()

        self.lblmsg["text"] = cli.insertCliente()

        self.txtcpf.delete(0, END)
        self.txtnome.delete(0, END)
        self.txttel.delete(0, END)

    def alterarCliente(self):
        cli = Clientes()

        cli.cpf = self.txtcpf.get()
        cli.nome = self.txtnome.get()
        cli.telefone = self.txttel.get()

        self.lblmsg["text"] = cli.updateCliente()

        self.txtcpf.delete(0, END)
        self.txtnome.delete(0, END)
        self.txttel.delete(0, END)

    def excluirCliente(self):
        cli = Clientes()

        cli.cpf = self.txtcpf.get()

        self.lblmsg["text"] = cli.deleteCliente()

        self.txtcpf.delete(0, END)
        self.txtnome.delete(0, END)
        self.txttel.delete(0, END)

    def buscarCliente(self):
        cli = Clientes()

        cpf = self.txtcpf.get()

        self.lblmsg["text"] = cli.selectCliente(cpf)

        self.txtcpf.delete(0, END)
        self.txtcpf.insert(INSERT, cli.cpf)

        self.txtnome.delete(0, END)
        self.txtnome.insert(INSERT, cli.nome)

        self.txttel.delete(0, END)
        self.txttel.insert(INSERT, cli.telefone)

    def Estoque(self, master2=None):
        self.fonte = ("Verdana", "8")
        root.iconbitmap('ico.ico')
        root.title("Cadastro de clientes: ")
        root.geometry("300x300")

        self.container1 = Frame(master2)
        self.container1["pady"] = 10
        self.container1.pack()
        self.container2 = Frame(master2)
        self.container2["padx"] = 20
        self.container2["pady"] = 5
        self.container2.pack()
        self.container3 = Frame(master2)
        self.container3["padx"] = 20
        self.container3["pady"] = 5
        self.container3.pack()
        self.container4 = Frame(master2)
        self.container4["padx"] = 20
        self.container4["pady"] = 5
        self.container4.pack()
        self.container5 = Frame(master2)
        self.container5["padx"] = 20
        self.container5["pady"] = 5
        self.container5.pack()
        self.container6 = Frame(master2)
        self.container6["padx"] = 20
        self.container6["pady"] = 5
        self.container6.pack()
        self.container7 = Frame(master2)
        self.container7["padx"] = 20
        self.container7["pady"] = 5
        self.container7.pack()
        self.container8 = Frame(master2)
        self.container8["padx"] = 20
        self.container8["pady"] = 10
        self.container8.pack()
        self.container9 = Frame(master2)
        self.container9["pady"] = 15
        self.container9.pack()

        self.titulo = Label(self.container1, text="Informe os dados :")
        self.titulo["font"] = ("Calibri", "9", "bold")
        self.titulo.pack()

        self.txtcdbarra = Label(self.container2,
                                text="cod barra:", font=self.fonte, width=10)
        self.txtcdbarra.pack(side=LEFT)

        self.txtcdbarra = Entry(self.container2)
        self.txtcdbarra["width"] = 15
        self.txtcdbarra["font"] = self.fonte

        self.txtcdbarra.pack(side=LEFT)

        self.btnBuscar = Button(self.container2, text="Buscar",
                                font=self.fonte, width=10)
        self.btnBuscar["command"] = self.buscarProd
        self.btnBuscar.pack(side=RIGHT)

        self.lblnome = Label(self.container3, text="Nome:",
                             font=self.fonte, width=10)
        self.lblnome.pack(side=LEFT)

        self.txtnome = Entry(self.container3)
        self.txtnome["width"] = 25
        self.txtnome["font"] = self.fonte
        self.txtnome.pack(side=LEFT)

        self.lblval = Label(self.container5, text="Valor:",
                            font=self.fonte, width=10)
        self.lblval.pack(side=LEFT)

        self.txtval = Entry(self.container5)
        self.txtval["width"] = 25
        self.txtval["font"] = self.fonte
        self.txtval.pack(side=LEFT)

        self.lbqtd = Label(self.container6, text="Quantidade:",
                           font=self.fonte, width=10)
        self.lbqtd.pack(side=LEFT)

        self.txtqtd = Entry(self.container6)
        self.txtqtd["width"] = 25
        self.txtqtd["font"] = self.fonte
        self.txtqtd.pack(side=LEFT)

        self.btnInsert = Button(self.container8, text="Inserir",
                                font=self.fonte, width=10)
        self.btnInsert["command"] = self.inserirProd
        self.btnInsert.pack(side=RIGHT)

        self.btnAlterar = Button(self.container8, text="Alterar",
                                 font=self.fonte, width=12)
        self.btnAlterar["command"] = self.alterarProd
        self.btnAlterar.pack(side=LEFT)

        self.btnExcluir = Button(self.container8, text="Excluir",
                                 font=self.fonte, width=12)
        self.btnExcluir["command"] = self.excluirProd
        self.btnExcluir.pack(side=LEFT)

        self.lblmsg = Label(self.container9, text="")
        self.lblmsg["font"] = ("Verdana", "9", "italic")
        self.lblmsg.pack()

    def inserirProd(self):
        prod = Produtos()

        prod.cdbarra = self.txtcdbarra.get()
        prod.nome = self.txtnome.get()
        prod.valor = self.txtval.get()
        prod.quantidade = self.txtqtd.get()

        self.lblmsg["text"] = prod.insertProd()

        self.txtcdbarra.delete(0, END)
        self.txtnome.delete(0, END)
        self.txtval.delete(0, END)
        self.txtqtd.delete(0, END)

    def alterarProd(self):
        prod = Produtos()

        prod.cdbarra = self.txtcdbarra.get()
        prod.nome = self.txtnome.get()
        prod.valor = self.txtval.get()
        prod.quantidade = self.txtqtd.get()

        self.lblmsg["text"] = prod.updateProd()

        self.txtcdbarra.delete(0, END)
        self.txtnome.delete(0, END)
        self.txtval.delete(0, END)
        self.txtqtd.delete(0, END)

    def excluirProd(self):
        prod = Produtos()

        prod.cdbarra = self.txtcdbarra.get()

        self.lblmsg["text"] = prod.deleteProd()

        self.txtcdbarra.delete(0, END)
        self.txtnome.delete(0, END)
        self.txtval.delete(0, END)
        self.txtqtd.delete(0, END)

    def buscarProd(self):
        prod = Produtos()

        cdbarra = self.txtcdbarra.get()

        self.lblmsg["text"] = prod.selectProd(cdbarra)

        self.txtcdbarra.delete(0, END)
        self.txtcdbarra.insert(INSERT, prod.cdbarra)

        self.txtnome.delete(0, END)
        self.txtnome.insert(INSERT, prod.nome)

        self.txtval.delete(0, END)
        self.txtval.insert(INSERT, prod.valor)

        self.txtqtd.delete(0, END)
        self.txtqtd.insert(INSERT, prod.quantidade)


root = Tk()
Application(root)
root.mainloop()```

1 answer

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.