0

I have been trying all the many examples in this website about switching windows in tkinter, but all I get is the buttons from the raised frame to be stacked on top, without "hiding" the other frames

Main screen :

import tkinter as tk
import Controller.ProdutoController as viewProduto

class Main:
    def __start__(self):

        self.roottk = tk.Tk()
        self.root = tk.Frame(self.roottk)

        self.root.pack(side="top", fill="both", expand=True)
        self.root.grid_rowconfigure(0, weight=1)
        self.root.grid_columnconfigure(0, weight=1)
        self.viewProduto = viewProduto.ProdutoController(self, self.root)
        self.viewMain = MainView(self, self.root)

        self.viewMain.tkraise()
        self.viewMain.master.master.title("Tela Principal")
        self.roottk.mainloop()



    def toprodutos(self):

        self.viewProduto.viewProduto.tkraise()

    def tomain(self):

        self.viewMain.tkraise()


class MainView(tk.Frame):

    def __init__(self, ct, root):
        tk.Frame.__init__(self,root)
        self.startUI()
        self.ct = ct
        self.grid( row = 0 , column = 0, sticky = "nsew")



    def startUI(self):

        botaoProdutos = tk.Button(self, text = "Produtos", command = self.toprodutos , padx = 5 , pady = 5)
        botaoProdutos.pack(side = "top")

        botaoEntrada = tk.Button(self, text="Entrada", command=self.toentrada, padx=5, pady=5)
        botaoEntrada.pack(side="top")

        botaoSaida = tk.Button(self, text="Saída", command=self.tosaida, padx=5, pady=5)
        botaoSaida.pack(side="top")

    def toprodutos(self):
        self.ct.toprodutos()
    def toentrada(self):
        return
    def tosaida(self):
        return

"Produtos" screen :

class ProdutoController:

    def __init__(self, viewMain, root):

        self.produtos = []
        self.viewMain = viewMain
        self.viewProduto = ProdutoView(root, self)


    def newproduto(self, nome, preco, quantidade):
        return

    def listprodutos(self):
        return

class ProdutoView(tk.Frame):
    def __init__(self, root, ct):
        tk.Frame.__init__(self, root)
        self.createWidgets()
        self.ct = ct
        self.grid(row = 0, column = 0)


    def createWidgets(self):

        self.list = tk.Button(self)
        self.list["text"] = "List"
        self.list["command"] = self.listProdutos
        self.list.pack(side="top")

    def listProdutos(self):
        self.ct.listprodutos()
Mojimi
  • 2,561
  • 9
  • 52
  • 116

1 Answers1

1

You aren't using the "sticky" attribute to force ProdutoView to fill the row and column that it is in.

class ProdutoView(tk.Frame):
    def __init__(self, root, ct):
        ...
        self.grid(row = 0, column = 0, sticky="nsew")
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685