You are on page 1of 19

import tkinter as tk

from tkinter import *


from tkinter import messagebox,ttk
import mysql.connector
import datetime
import serial

is_on = True
serial_ports=False
Produccion=False
Parada_Corta=False
Ventilacion=False
Secado=False
hab_ports=False
Tk_total=0
densidad=0
selection=0
cajas_total=0
Contadores_reset=False
envases=0
envases_D_V= 0
cajas=0
envases_D_LL=0
Lote_N=0
l='0'
k='0'
m='0'

ITEM_TBA2=['c','c','c','c','c','c','c','c','c','c','c','c','c','c','c','c']
ITEM_TBA1=['c','c','c','c','c','c','c','c','c','c','c','c','c','c','c','c']
ITEM_TSA21=['c','c','c','c','c','c','c','c','c','c','c','c','c','c','c','c']
ITEM_TWF67=['c','c','c','c','c','c','c','c','c','c','c','c','c','c','c','c']
ITEM_TCP70=['c','c','c','c','c','c','c','c','c','c','c','c','c','c','c','c']
def PLMS_PRODUCCION(a,b,c,d,e,f,g):
hora_actual=datetime.datetime.now()
hora_formateada=hora_actual.strftime('%H:%M %p')
Fecha_actual=datetime.datetime.now().date()
Val1=str(Fecha_actual)
mydb1 = mysql.connector.connect(
host="127.0.0.1",
user="root",
passwd="Jdrf15-*",#"Marjd15-",
database="plms_p"
)
mycursor1= mydb1.cursor()
sql1="INSERT INTO produccion
(Lote,Producto,No_Envases,D_vacios,D_llenos,No_Cajas,Turno,Fecha)
Values(%s,%s,%s,%s,%s,%s,%s,%s)";
val1=(a,b,c,d,e,f,g,Val1)
mycursor1.execute(sql1,val1)
mydb1.commit()
k=mycursor1.rowcount
return k
def PLMS_PROC1():
global envases
global envases_D_V
global cajas
global envases_D_LL
global Lote_N
global l
global j
global k
global h
global i
global m
#print('Envases=',envases)
#print('envases_D_V=',envases_D_V)
#print('cajas=',cajas)
#print('Lote=',Lote_N)
#print('envases_D_LL=',envases_D_LL)
#print('Producto=',selection)

hora_actual=datetime.datetime.now()
hora_formateada=hora_actual.strftime('%H:%M')
j='14:30'
h='22:30'
i='06:00'

print('---------------------------------------------------------------------')
print(hora_formateada)
print('L=',l)
print('H=',h)
print('K=',k)

print('---------------------------------------------------------------------')
if hora_formateada == j:
if l=='0':
turno= 'Primer Turno'
#print('Turno=',turno)
#Esc=PLMS_PRODUCCION(a,b,c,d,e,f,turno)

Esc=PLMS_PRODUCCION(Lote_N,selection,envases,envases_D_V,envases_D_LL,cajas,turno)
#list2[7]=str(Esc)
l='1'
m='0'
if hora_formateada == h:
if m=='0':
turno= 'Segundo Turno'
#Esc=PLMS_PRODUCCION(a,b,c,d,e,f,turno)
Esc=PLMS_PRODUCCION(Lote_N,selection,envases,envases_D_V,envases_D_LL,cajas,turno)
#list2[8]=str(Esc)
#print('Turno=',turno)
m='1'
k='0'
if hora_formateada == i:
if k=='0':
turno= 'Tercer Turno'
#Esc=PLMS_PRODUCCION(,b,c,d,e,f,turno)

Esc=PLMS_PRODUCCION(Lote_N,selection,envases,envases_D_V,envases_D_LL,cajas,turno)
#list2[9]=str(Esc)
print('Turno=',turno)
k='1'
l='0'
return
def reset_contadores():
global Contadores_reset
Contadores_reset=True
print('Contadores_reset=',Contadores_reset)

def PLMS(Userenter):
listdata=[]
D= Userenter
int_D=int(D)
i="{0:016b}".format(int_D)
lista=list(i)
lista.reverse()
lista2=[]
for i in range (16):
a=int(lista[i])
b= a&1
if b==0:
lista2.append('a')
else:
lista2.append(str(i))
return lista2

def PLMS_FALLA(Val):
mydb = mysql.connector.connect(
host="127.0.0.1",
user="root",
passwd="Jdrf15-*",#"Marjd15-",
database="plms_f"#"plmspython"
)
mycursor= mydb.cursor()
sql = "SELECT TBA0 FROM adq_plms where F= %s"#"SELECT TBA0 FROM adq_plms where F=
%s"
val=(Val,)
mycursor.execute(sql,val)
myresult = mycursor.fetchall()
b=str(myresult[0])
b = b.replace('(','')
b = b.replace(')','')
b = b.replace(',','')
b=b[1:-1]
return b
def PLMS_FALLA1(Val):
mydb = mysql.connector.connect(
host="127.0.0.1",
user="root",
passwd="Jdrf15-*",#"Marjd15-",
database="plms_f"#"plmspython"
)
mycursor= mydb.cursor()
sql = "SELECT TBA1 FROM adq_plms where F= %s"#"SELECT TBA0 FROM adq_plms where F=
%s"
val=(Val,)
mycursor.execute(sql,val)
myresult = mycursor.fetchall()
b=str(myresult[0])
b = b.replace('(','')
b = b.replace(')','')
b = b.replace(',','')
b=b[1:-1]
return b
def PLMS_FALLA2(Val):
mydb = mysql.connector.connect(
host="127.0.0.1",
user="root",
passwd="Jdrf15-*",#"Marjd15-",
database="plms_f"#"plmspython"
)
mycursor= mydb.cursor()
sql = "SELECT TBA2 FROM adq_plms where F= %s"#"SELECT TBA0 FROM adq_plms where F=
%s"
val=(Val,)
mycursor.execute(sql,val)
myresult = mycursor.fetchall()
b=str(myresult[0])
b = b.replace('(','')
b = b.replace(')','')
b = b.replace(',','')
b=b[1:-1]
return b
def PLMS_FALLA3(Val):
mydb = mysql.connector.connect(
host="127.0.0.1",
user="root",
passwd="Jdrf15-*",#"Marjd15-",
database="plms_f"#"plmspython"
)
mycursor= mydb.cursor()
sql = "SELECT TSA21 FROM adq_plms where F= %s"#"SELECT TBA0 FROM adq_plms where
F= %s"
val=(Val,)
mycursor.execute(sql,val)
myresult = mycursor.fetchall()
b=str(myresult[0])
b = b.replace('(','')
b = b.replace(')','')
b = b.replace(',','')
b=b[1:-1]
return b
def PLMS_FALLA4(Val):
mydb = mysql.connector.connect(
host="127.0.0.1",
user="root",
passwd="Jdrf15-*",#"Marjd15-",
database="plms_f"#"plmspython"
)
mycursor= mydb.cursor()
sql = "SELECT TWF67 FROM adq_plms where F= %s"#"SELECT TBA0 FROM adq_plms where
F= %s"
val=(Val,)
mycursor.execute(sql,val)
myresult = mycursor.fetchall()
b=str(myresult[0])
b = b.replace('(','')
b = b.replace(')','')
b = b.replace(',','')
b=b[1:-1]
return b
def PLMS_FALLA5(Val):
mydb = mysql.connector.connect(
host="127.0.0.1",
user="root",
passwd="Jdrf15-*",#"Marjd15-",
database="plms_f"#"plmspython"
)
mycursor= mydb.cursor()
sql = "SELECT TCP70 FROM adq_plms where F= %s"#"SELECT TBA0 FROM adq_plms where
F= %s"
val=(Val,)
mycursor.execute(sql,val)
myresult = mycursor.fetchall()
b=str(myresult[0])
b = b.replace('(','')
b = b.replace(')','')
b = b.replace(',','')
b=b[1:-1]
return b
def PLMS_REG(b):
hora_actual=datetime.datetime.now()
hora_formateada=hora_actual.strftime('%I:%M')
Val1=str(hora_formateada)
mydb1 = mysql.connector.connect(
host="127.0.0.1",
user="root",
passwd="Jdrf15-*",#"Marjd15-",
database="plms_r"
)
mycursor1= mydb1.cursor()
sql1="INSERT INTO table_reg (Descripcion,Inicio) SELECT %s,%s WHERE NOT EXISTS
(SELECT Descripcion FROM table_reg WHERE Final is NULL and Descripcion=%s)"
val1=(b,Val1,b)
mycursor1.execute(sql1,val1)
mydb1.commit()
k=mycursor1.rowcount
return k

def PLMS_REG_ITEM(b):
mydb2 = mysql.connector.connect(
host="127.0.0.1",
user="root",
passwd="Jdrf15-*",#"Marjd15-",
database="plms_r"
)
mycursor2= mydb2.cursor()
sql2="SELECT Item FROM table_reg WHERE Final IS NULL AND Descripcion =%s"
val2=(b,)
mycursor2.execute(sql2,val2)
myresult2 = mycursor2.fetchall()
e=str(myresult2[0])
e = e.replace('[','')
e = e.replace(']','')
e = e.replace('(','')
e = e.replace(')','')
e = e.replace(',','')
return e
def PLMS_UPDATE(b):
hora_actual=datetime.datetime.now()
hora_formateada=hora_actual.strftime('%I:%M')
Val2=str(hora_formateada)
Fecha_actual=datetime.datetime.now().date()
mydb2 = mysql.connector.connect(
host="127.0.0.1",
user="root",
passwd="Jdrf15-*",#"Marjd15-",
database="plms_r"
)
mycursor2= mydb2.cursor()
sql2="UPDATE `plms_r`.`table_reg` SET `Final` =%s, `Fecha` =%s WHERE `Final` is
NULL ";#"UPDATE `plms_r`.`table_reg` SET `Final` =%s, `Fecha` =%s WHERE (`Item`
=%s)and `Final` is NULL ";
val2=(Val2,Fecha_actual,b)
mycursor2.execute(sql2,val2)
mydb2.commit()
#myresult2 = mycursor2.fetchall()
#e=str(myresult2[0])
#e = e.replace('[','')
#e = e.replace(']','')
#e = e.replace('(','')
#e = e.replace(')','')
#e = e.replace(',','')
return #e
def PLM_PROC(a):
c=a
Fallas=[]
Reg_Falla=[]
for i in c:
Val= i
if Val!= 'a':
f=PLMS_FALLA(Val)
Fallas.append(f)
else:
Fallas.append('')
return Fallas
def PLM_PROC1(a):
c=a
Fallas=[]
Reg_Falla=[]
for i in c:
Val= i
if Val!= 'a':
f=PLMS_FALLA1(Val)
Fallas.append(f)
else:
Fallas.append('')
return Fallas
def PLM_PROC2(a):
c=a
Fallas=[]
Reg_Falla=[]
for i in c:
Val= i
if Val!= 'a':
f=PLMS_FALLA2(Val)
Fallas.append(f)
else:
Fallas.append('')
return Fallas
def PLM_PROC3(a):
c=a
Fallas=[]
Reg_Falla=[]
for i in c:
Val= i
if Val!= 'a':
f=PLMS_FALLA3(Val)
Fallas.append(f)
else:
Fallas.append('')
return Fallas
def PLM_PROC4(a):
c=a
Fallas=[]
Reg_Falla=[]
for i in c:
Val= i
if Val!= 'a':
f=PLMS_FALLA4(Val)
Fallas.append(f)
else:
Fallas.append('')
return Fallas
def PLM_PROC5(a):
c=a
Fallas=[]
Reg_Falla=[]
for i in c:
Val= i
if Val!= 'a':
f=PLMS_FALLA5(Val)
Fallas.append(f)
else:
Fallas.append('')
return Fallas

def read_serial_1():
global serial_ports
if serial_ports==False:
serial_ports= True
if serial_ports==True:
serial_ports= False

def read_serial():
global Produccion
global ITEM_TBA2
global Parada_Corta
global cajas_total
global Secado
global Contadores_reset
global envases
global envases_D_V
global cajas
global envases_D_LL
global Lote_N

#print('Contadores_reset=',Contadores_reset)
if Contadores_reset==False:
ser.write(b'h')
ser.flush()
if Contadores_reset==True:
ser.write(b'p')
ser.flush()
Contadores_reset=False
try:

datosASCII = ser.read(23)
#datosASCII = ser.readline()
#print(datosASCII )
RX_NEXT= (datosASCII[22])
#print(RX_NEXT)
if RX_NEXT==10:

envases=(datosASCII[0])+(datosASCII[1]*256)+(datosASCII[2]*65536)+(datosASCII[3]*16
777216)
envases_D_LL= (datosASCII[4])+(datosASCII[5]*256)
cajas= (datosASCII[6])+(datosASCII[7]*256)
envases_D_V= (datosASCII[8])+(datosASCII[9]*256)
TBA0= (datosASCII[10])+(datosASCII[11]*256)
TBA1= (datosASCII[12])+(datosASCII[13]*256)
TBA2= (datosASCII[14])+(datosASCII[15]*256)
TSA21= (datosASCII[16])+(datosASCII[17]*256)
TWF67= (datosASCII[18])+(datosASCII[19]*256)
TCP70= (datosASCII[20])+(datosASCII[21]*256)
rendimiento=(cajas/(cajas_total))*100
tiempo_prd=envases/7500
lbl4.config(text=str(envases))
lbl6.config(text=str(envases_D_V))
lbl8.config(text=str(envases_D_LL))
lbl10.config(text=str(cajas))#text=str(format
(und_total,'.2f'))
lblrdm_1.config(text=str(format(rendimiento,'.2f')))
lblprdcja_1.config(text=str(cajas))
lblTprd_1.config(text=str(format( tiempo_prd,'.2f')))
print('Envases=',envases)
print('envases_D_LL=',envases_D_LL)
print('envases_D_V=',envases_D_V)
F_TBA0=PLMS(TBA0)
F_TBA1=PLMS(TBA1)
F_TBA2=PLMS(TBA2)
F_TSA21=PLMS(TSA21)
F_TWF67=PLMS(TWF67)
F_TCP70=PLMS(TCP70)

RF_TBA0=PLM_PROC(F_TBA0)
RF_TBA1=PLM_PROC1(F_TBA1)
RF_TBA2=PLM_PROC2(F_TBA2)
RF_TSA21=PLM_PROC3(F_TSA21)
RF_TWF67=PLM_PROC4(F_TWF67)
RF_TCP70=PLM_PROC5(F_TCP70)

for i in RF_TBA0:
if i=="Producción":
Produccion=True
print('Produccion=',Produccion)
print('Parada Corta=',Parada_Corta)
#Parada_Corta=False
if i=="Parada Corta":
Produccion=False
Parada_Corta=True
print('Produccion=',Produccion)
print('Parada Corta=',Parada_Corta)
if i=="Secado":
Produccion=False
Parada_Corta=True
Secado=True
print('Secado=',Secado)

if Parada_Corta==True and Produccion==False:


"""
for j in range(16):
if RF_TBA1[j]!='':
f=PLMS_REG(RF_TBA1[j])
h=PLMS_REG_ITEM(RF_TBA1[j])
ITEM_TBA1[j]=str(h)
else:
ITEM_TBA1[j]=('b')
if RF_TBA2[j]!='':
f=PLMS_REG(RF_TBA2[j])
h=PLMS_REG_ITEM(RF_TBA2[j])
ITEM_TBA2[j]=str(h)
else:
ITEM_TBA2[j]=('b')

if RF_TSA21[j]!='':
f=PLMS_REG(RF_TSA21[j])
h=PLMS_REG_ITEM(RF_TSA21[j])
ITEM_TSA21[j]=str(h)
else:
ITEM_TSA21[j]=('b')

if RF_TWF67[j]!='':
f=PLMS_REG(RF_TWF67[j])
h=PLMS_REG_ITEM(RF_TWF67[j])
ITEM_TWF67[j]=str(h)
else:
ITEM_TWF67[j]=('b')

if RF_TCP70[j]!='':
f=PLMS_REG(RF_TCP70[j])
h=PLMS_REG_ITEM(RF_TCP70[j])
ITEM_TCP70[j]=str(h)
else:
ITEM_TCP70[j]=('b')
"""

except:
pass
#ser.flush()

PLMS_PROC1()
ventana.after(25, read_serial)

def seleccionports(event):
global ser
global hab_ports
selectionports=comboports.get()
ser = serial.Serial(port=selectionports, baudrate=9600, timeout=120,
write_timeout=1)
ser.close()
ser.open()
hab_ports=ser.is_open
print(ser.is_open)

def puertos_seriales():
ports = ['COM%s' % (i + 1) for i in range(256)]
encontrados = []
for port in ports:
try:
s = serial.Serial(port)
s.close()
encontrados.append(port)
except (OSError, serial.SerialException):
pass
return encontrados

def tk1_tk_2():
global selection
global densidad
global cajas_total
global Lote_N
Lote_N=numero.get()
Tk1_1=float(TK1.get())
Tk1_2=float(TK1_1.get())
Tk1_3=float(TK1_2.get())
Tk1_4=float(TK1_3.get())
Tk2_1=float(TK2.get())
Tk2_2=float(TK2_1.get())
Tk2_3=float(TK2_2.get())
Tk2_4=float(TK2_3.get())
Tk_total= Tk1_1+Tk1_2+Tk1_3+Tk1_4+Tk2_1+Tk2_2+Tk2_3+Tk2_4
lbltkg.config(text=str(format(Tk_total,'.2f')))
selection=combo.get()
if selection== "Manzana" or selection== "pera":
densidad= 0.207
if selection== "Durazno":
densidad= 0.212
if selection== "Guayaba/Piña":
densidad= 0.208
if selection== "Naranja":
densidad= 0.209
if densidad != 0:
und_total=(Tk_total/float(densidad))
cajas_total=und_total/27
lblund.config(text=str(format (und_total,'.2f')))
lblcja.config(text=str(format (cajas_total,'.2f')))

if selection== "":
if Tk_total==0:
densidad= 0
messagebox.showinfo(
message=f"Por favor seleccione un producto e ingrese
cantidad existente en los tanques ",title="Selección")
else:
densidad= 0
messagebox.showinfo(
message=f"Por favor seleccione un
producto",title="Selección")

else:
if Tk_total==0:
messagebox.showinfo(
message=f"Por favor ingrese cantidad existente en los
tanques",title="Selección")

return

def abrir_ventana_secundaria():
# Crear una ventana secundaria.
ventana_secundaria = tk.Toplevel()
ventana_secundaria.title("Reporte PLMSV_4")
ventana_secundaria.iconbitmap("kk.ico")
ventana_secundaria.config(width=300, height=200)
# Crear un botón dentro de la ventana secundaria
# para cerrar la misma.
boton_cerrar = ttk.Button(
ventana_secundaria,
text="Cerrar ventana",
command=ventana_secundaria.destroy
)
boton_cerrar.place(x=75, y=75)
##### VENTANA DEL PROGRAMA #####
ventana= tk.Tk()
ventana.title("PLMSV_4")
#ventana.geometry("800x500+300+100")
ventana.iconbitmap("kk.ico")
ventana.state('zoomed')
#ventana.configure(bg="silver")

#Crear Frame_1
Frame_1=LabelFrame(ventana,width="600", height="60",bd=5)
Frame_1.place(x=80,y=60)
#Creo la etiqueta
lbl = Label( text="PLMS TBA V 4.0",font = 'Helvetica 11 bold')
lbl.place(x=480,y=74)
# Cargar imagen del disco.
image = tk.PhotoImage(file="logo2.png")
# Insertarla en una etiqueta.

label = ttk.Label(image=image)
label.place(x=610,y=65)

ports=puertos_seriales()

comboports = ttk.Combobox(state="readonly",values=ports)
comboports.bind("<<ComboboxSelected>>", seleccionports)
comboports.place(x=90, y=74)

boton_1= Button(text="aceptar",width="10", height="1",command=read_serial)


boton_1.place(x=260, y=72)
boton_2= Button(text="stop",width="10", height="1",command=ventana.destroy)
boton_2.place(x=380, y=72)

#Crear Frame_2
Frame_2=LabelFrame(ventana,width="600", height="550",bd=5)
Frame_2.place(x=80,y=120)
#Crear Frame_3
Frame_3=LabelFrame(ventana,width="600", height="60",bd=5)
Frame_3.place(x=680,y=60)
#Crear Frame_4
Frame_4=LabelFrame(ventana,width="600", height="550",bd=5)
Frame_4.place(x=680,y=120)
#Creo la etiqueta_2
lb2 = Label( text="CONTROL DE PARADA TBA V 4.0",font = 'Helvetica 11 bold')
lb2.place(x=700,y=74)

########## CUADRO SEGUNDO ##########

lbl3_1= tk.Label(text="N0 Lote:",font="consolas 12",width=12,anchor=tk.W)


lbl3_1.place(x=86, y=150)
numero=ttk.Entry (width=22)
#Lote_N=Lote.get()
#Lote.insert(0, "0")
numero.place(x=90, y=170)
#Lote_N=Lote.get()
#print('revisar?',Lote_N)

lbl3_2= tk.Label(text="Producto:",font="consolas 12",width=12,anchor=tk.W)


lbl3_2.place(x=86, y=220)
combo = ttk.Combobox(state="readonly",values=["Manzana", "Pera", "Durazno",
"Guayaba/Piña","Naranja"],width=19)
combo.place(x=90, y=240)

lbl3= tk.Label(text="N0 Envases:",font="consolas 12",width=12,anchor=tk.W)


lbl3.place(x=86, y=290)
lbl4 = tk.Label(text="",bg="lightgrey",font="consolas 12 bold",width=15,relief =
tk.GROOVE)
lbl4.place(x=90,y=310)
image2 = tk.PhotoImage(file="image2.png")
label2 = ttk.Label(image=image2)
label2.place(x=234,y=300)
lbl5= tk.Label(text="D. Vacios:",font="consolas 12",width=12,anchor=tk.W)
lbl5.place(x=86, y=360)
lbl6 = tk.Label(text="",bg="lightgrey",font="consolas 12 bold",width=15,relief =
tk.GROOVE)
lbl6.place(x=90,y=380)
image3 = tk.PhotoImage(file="image3.png")
label3 = ttk.Label(image=image3)
label3.place(x=234,y=370)

lbl7= tk.Label(text="D. LLenos:",font="consolas 12",width=12,anchor=tk.W)


lbl7.place(x=86, y=430)
lbl8 = tk.Label(text="",bg="lightgrey",font="consolas 12 bold",width=15,relief =
tk.GROOVE)
lbl8.place(x=90,y=450)
image4 = tk.PhotoImage(file="image3.png")
label4 = ttk.Label(image=image4)
label4.place(x=234,y=440)

lbl9= tk.Label(text="N0 Cajas:",font="consolas 12",width=12,anchor=tk.W)


lbl9.place(x=86, y=500)
lbl10 = tk.Label(text="",bg="lightgrey",font="consolas 12 bold",width=15,relief =
tk.GROOVE)
lbl10.place(x=90,y=520)
image5 = tk.PhotoImage(file="caja.png")
label5 = ttk.Label(image=image5)
label5.place(x=234,y=505)

lbl11= tk.Label(text="Resetear Contadores",font="consolas 10",width=20,anchor=tk.W)


lbl11.place(x=87, y=590)
boton_2= Button(text="Reset",width="18",
height="1",command=reset_contadores)#reset_contadores
boton_2.place(x=90, y=615)

lbl11= tk.Label(text="Generar Reporte",font="consolas 10",width=20,anchor=tk.W)


lbl11.place(x=301, y=590)
boton_3= Button(text="Generar",width="14",
height="1",command=abrir_ventana_secundaria)
boton_3.place(x=304, y=615)

lblgc= tk.Label(text="Generar Cálculos",font="consolas 10",width=20,anchor=tk.W)


lblgc.place(x=500, y=590)
botongc= Button(text="aceptar",width="14", height="1",command=tk1_tk_2)
botongc.place(x=504, y=615)
lblTK1= tk.Label(text="TK1:",font="consolas 12",width=12,anchor=tk.W)
lblTK1.place(x=320, y=150)
TK1 = ttk.Entry (width=22)
TK1.insert(0, "0")
TK1.place(x=320, y=170)

TK1_1= ttk.Entry (width=22)


TK1_1.insert(0, "0")
TK1_1.place(x=320, y=220)

TK1_2 = ttk.Entry (width=22)


TK1_2.insert(0, "0")
TK1_2.place(x=320, y=270)

TK1_3 = ttk.Entry (width=22)


TK1_3.insert(0, "0")
TK1_3.place(x=320, y=320)

lblTK2= tk.Label(text="TK2:",font="consolas 12",width=12,anchor=tk.W)


lblTK2.place(x=520, y=150)
TK2 = ttk.Entry (width=22)
TK2.insert(0, "0")
TK2.place(x=520, y=170)

TK2_1 = ttk.Entry (width=22)


TK2_1.insert(0, "0")
TK2_1.place(x=520, y=220)

TK2_2= ttk.Entry (width=22)


TK2_2.insert(0, "0")
TK2_2.place(x=520, y=270)

TK2_3= ttk.Entry (width=22)


TK2_3.insert(0, "0")
TK2_3.place(x=520, y=320)

lbltkgl= tk.Label(text="Total kg:",font="consolas 12",width=12,anchor=tk.W)


lbltkgl.place(x=380, y=370)
lbltkg= tk.Label(text="",bg="lightgrey",font="consolas 12 bold",width=15,relief =
tk.GROOVE)
lbltkg.place(x=520,y=370)

lblestund= tk.Label(text="Estimado (und):",font="consolas 12",width=18,anchor=tk.W)


lblestund.place(x=380, y=415)
lblund= tk.Label(text="",bg="lightgrey",font="consolas 12 bold",width=15,relief =
tk.GROOVE)
lblund.place(x=520,y=415)

lblestcja= tk.Label(text="Estimado (cja):",font="consolas 12",width=18,anchor=tk.W)


lblestcja.place(x=380, y=455)
lblcja= tk.Label(text="",bg="lightgrey",font="consolas 12 bold",width=15,relief =
tk.GROOVE)
lblcja.place(x=520,y=455)

lblprdcja= tk.Label(text="P. Final (cja):",font="consolas 12",width=18,anchor=tk.W)


lblprdcja.place(x=380, y=500)
lblprdcja_1= tk.Label(text="",bg="lightgrey",font="consolas 12
bold",width=15,relief = tk.GROOVE)
lblprdcja_1.place(x=520,y=500)

lblrdm= tk.Label(text="Rendimiento(%):",font="consolas 12",width=18,anchor=tk.W)


lblrdm.place(x=380, y=545)
lblrdm_1= tk.Label(text="",bg="lightgrey",font="consolas 12 bold",width=15,relief =
tk.GROOVE)
lblrdm_1.place(x=520,y=545)

########## CUADRO TERCERO ##########


lblTprd= tk.Label(text="Tiempo Prod:",font="consolas 12",width=12,anchor=tk.W)
lblTprd.place(x=685, y=150)
lblTprd_1= tk.Label(text="",bg="lightgrey",font="consolas 12 bold",width=15,relief
= tk.GROOVE)
lblTprd_1.place(x=690,y=170)

lblTpar= tk.Label(text="Tiempo Paradas:",font="consolas 12",width=15,anchor=tk.W)


lblTpar.place(x=685, y=210)
lblTpar_1= tk.Label(text="",bg="lightgrey",font="consolas 12 bold",width=15,relief
= tk.GROOVE)
lblTpar_1.place(x=690,y=230)

lblnprd= tk.Label(text="N0 de Paradas:",font="consolas 12",width=15,anchor=tk.W)


lblnprd.place(x=685, y=270)
lblnprd_1= tk.Label(text="",bg="lightgrey",font="consolas 12 bold",width=15,relief
= tk.GROOVE)
lblnprd_1.place(x=690,y=290)

lblintg= tk.Label(text="N0 Interidad:",font="consolas 12",width=15,anchor=tk.W)


lblintg.place(x=865, y=150)
Lote = ttk.Entry (width=25)
Lote.place(x=869, y=170)

lblintg= tk.Label(text="N0 Microbiologia:",font="consolas 12",width=18,anchor=tk.W)


lblintg.place(x=865, y=210)
Lote = ttk.Entry (width=25)
Lote.place(x=869, y=230)
Frame_tabla=LabelFrame(ventana,width="590", height="320",bd=5)
Frame_tabla.place(x=685,y=345)

trv=ttk.Treeview(ventana,selectmode='browse',height="14")
trv.grid(row=1,column=1,columnspan=4,padx=690,pady=350)
# set columns and headings for Treeview

trv["columns"]=("1","2","3","4","5")
trv['show']='headings'
trv.column("1",width=65,anchor='c')
trv.column("2",width=280,anchor='c')
trv.column("3",width=70,anchor='c')
trv.column("4",width=70,anchor='c')
trv.column("5",width=70,anchor='c')
trv.heading("1",text="Item")
trv.heading("2",text="Descripcion")
trv.heading("3",text="Inicio")
trv.heading("4",text="Final")
trv.heading("5",text="Fecha")

"""
mydb = mysql.connector.connect(
host="127.0.0.1",
user="root",
passwd="Marjd15-",
database="plms_r"
)
"""

mydb = mysql.connector.connect(
host="127.0.0.1",
user="root",
passwd="Jdrf15-*",
database="plms_r"
)
#"""
mycursor= mydb.cursor()
sql = "SELECT * FROM table_reg"
mycursor.execute(sql,)
myresult = mycursor.fetchall()
# Adding rows of data from MySQL student table to treeview
for row in myresult:
trv.insert("", 'end',iid=row[0], text=row[0],
values =list(row))
vs = ttk.Scrollbar(Frame_tabla,orient="vertical", command=trv.yview)#V Scrollbar
trv.configure(yscrollcommand=vs.set) # connect to Treeview
#vs.grid(row=1,column=1,sticky='ns',padx=200,pady=40)
vs.place(x=560,y=5, height=300)
print(serial_ports)
if serial_ports==True:
ventana.after(25, read_serial)

ventana.mainloop()
ser.close()

You might also like