Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 标签更新过于频繁_Python_Tkinter_Label - Fatal编程技术网

Python 标签更新过于频繁

Python 标签更新过于频繁,python,tkinter,label,Python,Tkinter,Label,每次输入数字时,批次中的标签都会更新。我知道这是预期的工作方式,但当我在条目中输入9999时,它将更新4次,每次它从4000-5000个条目的字典中搜索时,它会被卡住1秒。输入4个字符后,如何使其更新?或在单击下一个条目时更新。我不想一按按钮就更新它。我最后因为找不到钥匙而犯了很多错误 Exception in Tkinter callback Traceback (most recent call last): File "C:\Users\prepa\Desktop\stic\Inter

每次输入数字时,批次中的标签都会更新。我知道这是预期的工作方式,但当我在条目中输入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()
输入4个字符后,如何使其更新

只需检查输入了多少个字符,并且只有在有四个字符时才进行操作

def BatchInput(a, b, c): 
    e2 = e2var_get()
    if len(e2) < 4:
        return
    ...
def批处理输入(a、b、c):
e2=e2var_get()
如果len(e2)<4:
返回
...

减少代码以仅保留重要元素。也许当你减少它时,你就会看到问题出在哪里。顺便说一句:使用
len(text)>=4
检查你是否有4个字符。