Tkinter (Python) Windows Management

1

I'm doing a code in which the main window has 4 buttons (Create, Manage, Delete and About) and I wanted the time I clicked the button to create isse for the creation tab without having to open another window (Stay two windows) or close the main and open and another (ie close and open). Type the Ccleaner, you click and setup, there in the same window it leaves the part of analyze and opens the configuration.

Code:

from tkinter import *
from sqlite3 import *

class criar(object):
    def __init__(self, principal):
#frames e empacotamento de frames
        self.frame1 = Frame(principal)
        self.frame1.place()
        self.frame1.pack()
        self.frame2 = Frame(principal)
        self.frame2.place()
        self.frame2.pack()
        self.subFrameOptions = Frame(self.frame2)
        self.subFrameOptions.place()
        self.subFrameOptions.pack()
#texto exibido na tela
        L1 = Label(self.frame1, text = "Nome do Seu Banco de Dado")
        L1.place(x = 10,y = 10)
        L1.pack()
        E1 = Entry(self.frame1, bd = 5, )
        E1.place(x = 60,y = 10)
        E1.pack()
#checkButtons
        self.nome = Checkbutton(self.subFrameOptions, bd = 5, text = 'Nome', variable = Vnome)
        self.nome.pack(side = LEFT)
        Vnome.get()
        self.cor = Checkbutton(self.subFrameOptions, bd = 5, text = 'Cor', variable = Vcor)
        self.cor.pack(side = LEFT)
        Vcor.get()
        self.cpf = Checkbutton(self.subFrameOptions, bd = 5, text = 'CPF', variable = Vcpf)
        self.cpf.pack(side = LEFT)
        Vcpf.get()
        self.email = Checkbutton(self.subFrameOptions, bd = 5, text = 'Email', variable = Vemail)
        self.email.pack(side = LEFT)
        Vemail.get()


principal = Tk()
#variaveis dos metodos dos checkButtons
Vnome = IntVar()
Vcor = IntVar()
Vcpf = IntVar()
Vemail = IntVar()
#cria a instancia
criar(principal)
principal.geometry('400x300')
principal.title("Gerenciador de Cadastro")
principal.mainloop()

Now you can see that I want to create a database manager program in which the user enters the name of the database and marks the options that have been entered. so I want to do something like this (Pseudo code): I click on the create button I place the name of the database in the database and then I send the code and I go into the management to look at the created database, but I do not want the program to open and close window, I want the same window to change tab.

    
asked by anonymous 16.05.2017 / 01:31

1 answer

2

You can use .pack_forget() to delete the widget you gave .pack() and then give .pack() to another widget you'd like to stay in that frame.

Example:

I hope I've become clearer with this example.

from tkinter import *

class exemplo:
    def __init__(self, tk):
        self.frame1 = Frame(tk)
        self.frame2 = Frame(tk)
        self.frame3 = Frame(tk)

        self.frame1.pack()
        self.frame2.pack()
        self.frame3.pack()

        self.Botao1 = Button(self.frame1, text='Clique nesse botão para alterar.', command=self.alterar, bg='darkred')
        self.entrada1 = Label(self.frame2, text='Usuário:', width=8, height=2)
        self.entrada2 = Entry(self.frame2)

        self.Botao1.pack()
        self.entrada1.pack(side=LEFT)
        self.entrada2.pack(side=LEFT)

    def alterar(self):
        self.Botao1.pack_forget() #Retiro todos esses
        self.entrada1.pack_forget() #Retiro todos esses
        self.entrada2.pack_forget() #Retiro todos esses

        # E no frame aonde os três acima estavam, eu coloquei esses:
        self.Botao2 = Button(self.frame3, text='Clique nesse botão para voltar.', command=self.reverter, bg='darkgray')
        self.entrada3 = Label(self.frame2, text='Digite algo acima', height=2)
        self.entrada4 = Entry(self.frame1)

        self.Botao2.pack()
        self.entrada3.pack(side=LEFT)
        self.entrada4.pack(side=LEFT)

    def reverter(self):
        self.Botao1.pack() # Para reverter eu simplesmente dei .pack() nesses
        self.entrada1.pack() # Para reverter eu simplesmente dei .pack() nesses
        self.entrada2.pack() # Para reverter eu simplesmente dei .pack() nesses

        self.Botao2.pack_forget() # e "eliminei esses". Se isso não for feito, ambos ocupam o mesmo Frame.
        self.entrada3.pack_forget() # e "eliminei esses". Se isso não for feito, ambos ocupam o mesmo Frame.
        self.entrada4.pack_forget() # e "eliminei esses". Se isso não for feito, ambos ocupam o mesmo Frame.
ex = Tk()
exemplo(ex)
ex.mainloop()
    
16.05.2017 / 02:27