code:
def editar (self, event=None):
ob = self.buffer(opcao=2)
if (ob[1] == None):
return
elif (ob[0] == None):
return
root = Tk()
root.withdraw()
for o in self.lista:
if (ob[0].codigo.upper() == o.codigo):
#solicita a certeza do usuário quanto à edição
v = askyesnocancel('Primeira rodada',
message='Voce tem certeza?\n'+
str(ob[1].semestre) +
'\n'+ob[1].nome_completo.upper() +
'\n'+ob[1].requisitos.upper() +
'\n'+str(ob[1].horas) +
'\n'+ob[1].estado_atual.upper() +
'.')
if (v):
dic = Disciplina(ob[1].semestre,
o.codigo,
ob[1].nome_completo.upper(),
ob[1].horas,
ob[1].requisitos.upper(),
ob[1].estado_atual.upper())
ind = lista.index(o)
self.lista.pop(ind)
self.lista.insert(ind, dic)
break
This code is responsible for editing a Discipline object, in which it simply removes the object from the list and inserts a similar object in the same position.
Everything here works perfectly well. But the window that details the object and contains the button it calls by this function remains open. Since it should call this function and close the window to return to the initial window, which is a list of all objects.
The function calling by the above function:
def detalha (self, event=None, opcao='Editar'):
self.janela.iconify() #minimiza a janela principal
if (not 'adiciona' in opcao.lower()):
item = self.listar.get(self.listar.curselection()[0])
t = ler.achaMat(item.split(' ')[1][:6], self.lista)[1]
det = Det(t.semestre, t.codigo, t.nome_completo,
t.horas, t.requisitos, t.estado_atual, opcao)
det.janela.wm_protocol("WM_TAKE_FOCUS", det.imprime)
else:
det = Det(tp=opcao) #tp é o que será mostrado no botao
if ('edita' in opcao.lower()):
det.botao.bind("<ButtonRelease-1>", self.editar)
elif ('exclui' in opcao.lower()):
det.botao.bind("<ButtonRelease-1>", self.excluir)
elif ('adiciona' in opcao.lower()):
det.botao.bind("<ButtonRelease-1>", self.adiciona)
#Mostra a janela principal e reseta a lista
det.janela.bind("<Destroy>", self.reseta)
Before asking, the button calls the action (self, event = None) and at the end of it has the call to another function self.fecha () that has as code:
def fecha (self, event=None):
self.janela.destroy()