我创建了一个程序,当单击其中一个按钮时,它会更改框架,其中包含其他功能。
我尝试使用['frame']
.config
,这是一个简单的功能,但是没有用。
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)
我希望通过单击相应的按钮,框架会发生变化,而彼此之间不会重叠