Метка из пакета обновляется каждый раз, когда я ввожу номер. Я знаю, что это намеченный способ работы, но когда я ввожу 9999 при вводе, он обновляется 4 раза, и каждый раз, когда он ищет в словаре 4000-5000 записей, он застревает на 1 секунду. как я могу обновить его только после ввода 4 символов? или обновить, когда я нажму на следующую запись. Я не хочу обновлять его нажатием кнопки. Я заканчиваю с большим количеством ошибок из-за того, что не могу найти ключ
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\prepa\Desktop\stic\Interpretor\Python38-32\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "C:/Users/prepa/Desktop/stic/Database/database.py", line 63, in SelEtapa
raise NotImplementedError("Method %s not implemented" % method_name)
NotImplementedError: Method H not implemented
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\prepa\Desktop\stic\Interpretor\Python38-32\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "C:/Users/prepa/Desktop/stic/Database/database.py", line 52, in BatchInput
batch.set(d[p])
KeyError: '4.0'
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\prepa\Desktop\stic\Interpretor\Python38-32\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "C:/Users/prepa/Desktop/stic/Database/database.py", line 52, in BatchInput
batch.set(d[p])
KeyError: '44.0'
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\prepa\Desktop\stic\Interpretor\Python38-32\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "C:/Users/prepa/Desktop/stic/Database/database.py", line 52, in BatchInput
batch.set(d[p])
KeyError: '444.0'
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\prepa\Desktop\stic\Interpretor\Python38-32\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "C:/Users/prepa/Desktop/stic/Database/database.py", line 52, in BatchInput
batch.set(d[p])
KeyError: '4444.0'
Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Users\prepa\Desktop\stic\Interpretor\Python38-32\lib\tkinter\__init__.py", line 1883, in __call__
return self.func(*args)
File "C:/Users/prepa/Desktop/stic/Database/database.py", line 52, in BatchInput
batch.set(d[p])
KeyError: '44444.0'
Вот мой код
from tkinter import * #Import modul
import pandas as pd #Import modul
import xlsxwriter #Import modul
from openpyxl.cell import cell
from openpyxl.styles import Alignment
from pandas import ExcelWriter #Import modul
import openpyxl #Import modul
from string import digits
from openpyxl.styles import Alignment
import xlrd
##################################################################################
H88888 = {
"0": "aa",
"5": "bb",
"9": "cc",
"16": "dd",
"15": "ee",
"19": "ff",
"21": "gg",
"23": "hh",
"24": "ii",
"26": "jj",
"27": "kk",
"28": "ll",
"30": "mm",
"33": "nn",
"37": "oo"
}
def NumeAngajati(a, b, c): # trace send 3 arguments to my_tracer
print(e1_var.get())# #Definire Nume Angajatiw
if e1_var.get() == "0":
print("00")
angajat.set("Introdu codul")
elif e1_var.get() == "1":
angajat.set("bbbbbbbb bbbbbbbbbb")
elif e1_var.get() == "2":
angajat.set("Aaaaaaaaa Aaaaaaaaaa")
###############################################################################################################################
def BatchInput(a, b, c): # trace send 3 arguments to my_tracer #Definire Introducre Batch
d = {}
wb = xlrd.open_workbook('excel2.xlsx')
sh = wb.sheet_by_index(0)
for i in range(3, sh.nrows):
cell_value_class = str(sh.cell(i, 0).value)
cell_value_id = str(sh.cell(i, 1).value)
d[cell_value_class] = cell_value_id
p = str(e2_var.get() + ".0")
batch.set(d[p])
print(batch.get()[-6:])
############################################################################################################################
def SelEtapa(a, b, c):
method_name = str("H" + batch.get()[-6:]) # set by the command line options
possibles = globals().copy()
possibles.update(locals())
d = possibles.get(method_name)
if not d:
raise NotImplementedError("Method %s not implemented" % method_name)
p = str(e3_var.get())
print(p)
etapa.set(d[p])
def write_to_xlsx():
print(pv.get())
if pv.get() == 1:
print("On")
else:
print("Off")
wb = openpyxl.load_workbook('excel.xlsx') # selectie fisier
sheet = wb["Productie"]
angajat = float(EntryAngajat.get())
etapa = EntryEtapa.get()
batch = EntryBatch.get()
cantitate = EntryCantitate.get()
if pv.get() == 1:
print("On")
else:
EntryAngajat.delete(0, END)
EntryAngajat.insert(0, 0)
EntryEtapa.delete(0, END)
EntryEtapa.insert(0, 0)
EntryBatch.delete(0, END)
EntryBatch.insert(0, 0)
EntryCantitate.delete(0, END)
EntryCantitate.insert(0, 0)
ws = wb.active
maxim = ws.max_row + 1
from openpyxl.styles import Alignment
ws.cell(column=1, row=maxim, value=int(batch))
ws.cell(column=3, row=maxim, value=int(etapa))
ws.cell(column=4, row=maxim, value=int(cantitate))
ws.cell(column=5, row=maxim, value=int(angajat))
rows = range(1, maxim + 1)
columns = range(1, 8)
for row in rows:
for col in columns:
sheet.cell(row, col).alignment = Alignment(horizontal='center', vertical='center', wrap_text=True)
wb.save("excel.xlsx")
def export():
print("Export")
def calitate():
print("Calitate")
##################################################################################################################
root = Tk()
root.geometry("330x400")
menubar = Menu(root)
filemenu = Menu(menubar,tearoff = 0)
filemenu.add_command(label = "Export", command = export )
filemenu.add_command(label = "Calitate", command = calitate)
menubar.add_cascade(label = "File", menu=filemenu)
small_font=("Verdana",5)
medium_font=("Verdana",10)
large_font = ('Verdana',15)
label_font = ("Verdana",14)
##################################################################################################################
Titlu=Label(root,text=" test",font=medium_font,)
Titlu.grid(row=1 ,column=1,sticky="E")
###################################################################################################################
print(A)
LabelA = Label(root, text="Operator",font=large_font)
LabelA.grid(row=2 ,column=1)
angajat = StringVar()
LabelAngajat = Label(root, textvariable=angajat, font=label_font)
LabelAngajat.grid(row=3 ,column=2,sticky="W")
e1_var = StringVar() # or StringVar(top)
e1_var.trace('w', NumeAngajati) # run my_tracer if value was changed (w = write)
EntryAngajat = Entry(root, textvariable=e1_var,width=8 ,font=large_font)
EntryAngajat.grid(row=3 ,column=1)
####################################################################################################################
LabelB= Label(root, text = "Batch",font=large_font)
LabelB.grid(row=5 ,column=1)
batch = StringVar() # or StringVar(top)
LabelBatch = Label(root, textvariable=batch, font= label_font)
LabelBatch.grid(row=6 ,column=2,sticky="W")
e2_var = StringVar() # or StringVar(top)
e2_var.trace('w', BatchInput) # run my_tracer if. value was changed (w = write)
e2_var.trace('r', SelEtapa)
EntryBatch = Entry(root, textvariable=e2_var,width=8,font=large_font)
EntryBatch.grid(row=6 ,column=1)
#####################################################################################################################
LabelC=Label(root, text="Etapa",font=large_font)
LabelC.grid(row=8 ,column=1)
etapa = StringVar() # or StringVar(top)
LabelEtapa = Label(root, textvariable=etapa , font=label_font)
LabelEtapa.grid(row=9 ,column=2)
e3_var = StringVar() # or StringVar(top)
e3_var.trace('w', SelEtapa) # run my_tracer if value was changed (w = write)
EntryEtapa = Entry(root, textvariable=e3_var,width=8,font=large_font)
EntryEtapa.grid(row=9 ,column=1)
######################################################################################################################
LabelD= Label(root,text = "Cantitate",font=large_font)
LabelD.grid(row=11 ,column=1)
EntryCantitate = Entry(root,width=8,font=large_font)
EntryCantitate.grid(row=12 ,column=1)
pv = IntVar()
r = Checkbutton(root, text="Pastreaza valorile ", variable=pv)
r.grid(row=13 ,column=1)
#######################################################################################################################
Submit =Button(root, text="Submit", command=write_to_xlsx)
Submit.grid(row=14 ,column=1)
root.config(menu=menubar)
root.mainloop()