0
因此,我正在研究Tkinter,我的目標是當用戶按下一個按鈕時,它會打開一個新窗口,他可以在數據庫中插入數據,然後再次填充表,以顯示插入的新數據。新窗口打開正常,數據確實插入,但列表未更新,我不知道爲什麼。無法按順序運行功能。 Python
按鈕代碼:
self.inserir = Button(self.container2, text="Inserir", command=lambda:self.help(tm.FazTela(bd),self.populate()))
是可以獲得的功能列表,並運行這些功能代碼:
def help(*functions):
def func(*args, **kwargs):
return_value = None
for function in functions:
return_value = function(*args, **kwargs)
return return_value
return func
如果我產生窗函數之前調用填入功能,它運行很好但這不是我想要的,我想在用戶輸入數據後更新。
我不知道是否有幫助,但這裏的,一旦按下按鈕打開的窗口中的代碼:
from Tkinter import *
from database import database as db
from database import tratamentos as tr
import tkMessageBox
class TelaMenor():
def __init__(self):
self.root = None
self.OPTIONS = []
self.cor1 = '#D32F2F'
def CloseWindow(self):
self.root.destroy()
self.root = None
def SendToTR(self,nome,valor,tipo,bd):
try:
tr.ProdutosRecieve(nome,valor,tipo,bd)
except:
tkMessageBox.showerror("Erro encontrado", "Digite valores validos!")
finally:
self.CloseWindow()
def FazTela(self,bd):
if(self.root!=None):
self.CloseWindow()
self.FazTela()
else:
self.root=Tk()
# opcoes do droplist
self.OPTIONS = [
"Tipo de produto",
"Doce",
"Salgado",
"Massa",
"Bebida",
"Outro"
]
#fim
# criacao e posicao dos widgets
info = Frame(self.root)
info.grid(sticky=N+S+W+E)
salto1 = Label(info, text=" ")
salto1.grid(row=0, column=0)
nome1 = Label(info, text="Nome:")
nome1['font']=['bold']
nome1.grid(row=1, column=1, sticky=W)
nome2 = Entry(info)
nome2["width"]=40
nome2.grid(row=2, column=1)
salto2 = Label(info, text="")
salto2.grid(row=3, column=0)
valor1 = Label(info, text="Valor:")
valor1['font']=['bold']
valor1.grid(row=4, column=1, sticky=W)
valor2 = Entry(info)
valor2["width"]=40
valor2.grid(row=5, column=1)
salto3 = Label(info, text="")
salto3.grid(row=6, column=0)
variable = StringVar(info)
variable.set(self.OPTIONS[0])
droplist = apply(OptionMenu, (info, variable) + tuple(self.OPTIONS))
droplist.grid(row=7, column=1)
salto4 = Label(info, text="")
salto4.grid(row=8, column=0)
pronto = Button(info, text="Pronto", bg=self.cor1, bd=3,command=lambda: self.SendToTR(nome2.get(),valor2.get(),variable.get(),bd))
pronto['font']=['bold']
pronto['fg']='white'
pronto.grid(row=9, column=1)
salto5 = Label(info, text="")
salto5.grid(row=10, column=1)
espaco1 = Label(info, text=" ")
espaco1.grid(row=10, column=2)
#fim
# barra de "status"
status = Label(info, text="Estado: Normal", bg="white", bd=1, relief=SUNKEN, anchor=W)
status.grid(row= 11, column=0, sticky=S+W+E, columnspan=3)
#fim
# formatacao da janela
self.root.title('Cadastro do Produto')
#root.iconbitmap(r'c:\Python27\DLLs\icon.ico')
self.root.resizable(width=False, height=False)
self.root.geometry('298x276')
self.root.protocol("WM_DELETE_WINDOW",lambda: self.CloseWindow())
self.root.mainloop()
#fim
對不起,有一些葡萄牙語。