程序运行正常,但是当我在输入框中输入名称并单击搜索按钮时,它显示以下错误:
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\Familiar\AppData\Local\Programs\Python\Python37-32\lib\tkinter\__init__.py", line 1705, in __call__
return self.func(*args)
File "C:\Users\Familiar\Google Drive\Office Sync\Python programs and exercises\CAdminGUI.py", line 41, in findclient
print(clientes[crit])
NameError:
name 'crit' is not defined
下面您将找到我使用的代码:
#!/usr/bin/python3
from tkinter import *
from tkinter import ttk
class BuscarCl:
def __init__(self,master):
self.label = ttk.Label(master, text = 'Administrador De Clientes')
self.label.grid(row = 0, column = 0, columnspan = 2)
#Nombre del cliente
entry = ttk.Entry(master, width = 30)
entry.grid(row = 1, column = 1)
entry.insert(INSERT, "Nombre y apellido a buscar ")
crit = entry.get()
entry2 = ttk.Entry(master, width = 50)
entry2.grid(row = 2, column = 1)
entry2.insert(INSERT, "Escriba el nombre del cliente a agregar ")
entry3 = ttk.Entry(master, width = 80)
entry3.grid(row = 3, column = 1)
entry3.insert(INSERT, "Escriba la info de cliente separada por
espacios ")
srchbutton = ttk.Button(master, text = "Buscar",
command = self.findclient).grid(row = 1, column= 2 )
addbutton = ttk.Button(master, text = "Ingresar Cliente",
command = self.addclient).grid(row = 3, column = 0)
def findclient(self):
print(clientes[crit])
def addclient(self):
custinfo = []
for infor in entry2.split():
custinfo.append(infor)
clientes[entry2] = entry3
clientes = {'ricardo guerrero':['11206709', 'Nueva_Eps', 'Riesgo4',
'Compensar', 'colpensiones'], 'doris santos' : ['52301828', 'Nueva_Eps',
'Riesgo: 1']}
def main():
root = Tk()
app = BuscarCl(root)
root.mainloop()
if __name__ == "__main__": main()