0

I created a program that when clicking on one of the buttons, it changes the frame, which contains other functions.

I tried to use ['frame'] .config, a simple function of the same, but nothing works.

from tkinter import *
from Item import Item
from Monstro import Monster

class Ferramentas:

    def __init__(self,master,Item,Monster):

        self.Item = Item
        self.Monster = Monster

        self.ferramentas = Frame(master)
        self.ferramentas.grid(row=0,column=0)

        self.b1 = Button(self.ferramentas,text='CALCULADORA')
        self.b2 = Button(self.ferramentas,text='MONSTROS',command=self.Monstros)
        self.b3 = Button(self.ferramentas,text='ITENS',command=self.Itens)


        self.b1.grid(row=0,column=0)
        self.b2.grid(row=0,column=1)
        self.b3.grid(row=0,column=2)

        self.frame_mestre = Frame(master)
        self.frame_mestre.grid(row=1,column=0)

    def Itens(self):
        self.frame_mestre = self.Item.frame_2
        self.Item.frame_2.grid(row=1,column=0,sticky="nsew")

    def Monstros(self):
        self.frame_mestre = self.Monster.frame_1
        self.Monster.frame_1.grid(row=1,column=0,sticky="nsew")


janela = Tk()
c = Monster(janela)
b = Item(janela)
a = Ferramentas(janela,b,c)
janela.mainloop()
class Item:

    def __init__(self,master):

        self.frame_2 = Frame(master)

        self.item_nome = Label(self.frame_2, text='NOME')
        self.item_nome.grid(row=0,column=1)
class Monster:

    def __init__(self, master):
        self.frame_1 = Frame(master)

        self.nome = Label(self.frame_1, text='NOME', relief='raised')
        self.nome.grid(row=0,column=1, columnspan=2)

I hope that by clicking on the respective button, the frames change, without one overlapping the other

RATO
  • 45
  • 6
  • Check this post https://stackoverflow.com/questions/7546050/switch-between-two-frames-in-tkinter. – Saad Apr 21 '19 at 07:21
  • if you use `grid()` to show widget then you can use `grid_forget()` to remove it from window but not from memory so you can `grid()` it again. The same with `pack()` and `pack_forget()`. – furas Apr 21 '19 at 15:06
  • sorry, but i still don't know how to do this – RATO Apr 21 '19 at 16:02

0 Answers0