Tkinter Window Management (Python)

Asked

Viewed 7,183 times

2

i am making a code in which the main window has 4 buttons (Create, Manage, Delete and About) and I wanted at the time I click the button create isse to the creation tab without having to open another window(Stay two windows) or close the main and open and other(i.e., closes and opens). Type the Ccleaner, Voce click and configuration, then in the same window it leaves the parsing part 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()

Then you can see that I want to create a database manager program in which the user type the name of the database and marks the options typed. I want to do something like (Pseudo code): I click on the button creates the name mark the options of data in the database and then send the code and already enter the management to look at the database created, but I do not want the program to keep opening and closing window, I want it to change tab in the same window.

  • Since you registered today on the site, I recommend that you first do the [tour] to understand at least the basics of how the system works. After, you can [Dit] the question and add the code you already have so that we can better understand what you have done and need to do. For code formatting, just copy it in the question editor, select it and press Ctrl+K.

  • ready I tidied up the question

1 answer

2


you can use .pack_forget() to delete the widget you gave .pack() and then give .pack() in another widget that you would like to be in that frame.

Example:

I hope I’ve been 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()
  • Helped a lot vlw

  • you could help me with another problem please ?

  • If I can help you I don’t know much about Tkinter.

  • https://answall.com/questions/204894/bot%C3%A3o-send-or-update-no-Tkinter-python-e-resize-of-widgets

Browser other questions tagged

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