hello friends,
I have been working on a program (Python language) which can receive data for a tkinter GUI, with the main proposal, to make math operations.
The program is divided into a few parts. First you will see a structure like a table, composed of 5 columns. Actually each column is dictionary.
After the table you will see a button, when user click on it, activate the GuardarDatos() function, and inside of this one, every dictionary send information to make a list, to finally try to make some math calculation between lists (sum and multiply).
What are my problems?
-
I tried many forms to make the math operation between list, but the result is like a string grouping. In other word if "suministros[1] = 1" and "mano_obra[1] = 1", and I tried to make a "sum", the result is "11", not number "2".
-
I want to put the result of math operations in respective column ("unitario" and "valor total"), but i cant use de "set method".
I would appreciate all the help provided
My code:
from tkinter import*
from math import *
import operator
root = Tk()
root.title("Window")
root.geometry("800x600")
labelframe1 = LabelFrame(root, text="Table for operations")
labelframe1.pack()
############################################################################
# ---------------- VARIABLE DECLARATION ------------------------------
############################################################################
cantidad = []
valor_unitario = []
total_parcial = []
suministros = []
mano_obra = []
###################################################################################
# ============================= FUNCTION ====================================
###################################################################################
def GuardarDatos():
for key in entries_suministros:
suministros.append(entries_suministros[key].get())
print("suministros: ", suministros)
print("=====================")
for key in entries_mo:
mano_obra.append(entries_mo[key].get())
print("mano de obra: ", mano_obra)
print("=====================")
print("==== unitarios ========")
valor_unitario = list(map(operator.add, suministros,
mano_obra))
print("valor unitario: ", valor_unitario)
print("==== totales parciales ======")
total_parcial = list(map(operator.mul, valor_unitario,
cantidad))
print("totales parciales:", total_parcial)
########################################################################################
# ANOTHER OPTION TO MAKE MATH OPERATION --- IT DOES NOT WORKED
#######################################################################################
# def add(suministros, mano_obra):
# for x in range(0, len(suministros)):
# loco = (suministros[x]) + (mano_obra[x])
# valor_unitario.append(loco) # Suma Strings
# Letrero_unit.config(text=valor_unitario)
# print(valor_unitario[x])
# return valor_unitario # Con el returno me pone 1 en posicion "[0]"
####################################################################################
# ======================== TABLE STRUCTURE ===================================
####################################################################################
# COLUMN 1: CANTIDAD =======================
entries_cant = {}
for row0 in range(0, 3):
datosEntry0 = Label(labelframe1, text="cantidad") # Label
datosEntry0.grid(row=0, column=0, sticky="nsew") # Label
datosEntry0 = Entry(labelframe1) # Entry
datosEntry0.grid(row=row0, column=0) # Entry
entries_cant["Entrybox{0}".format(row0)] = datosEntry0 # Entry
# COLUMN 2: UNITARIOS =================
for row1 in range(3):
datosEntry1 = Label(labelframe1, text="Unitario")
datosEntry1.grid(row=0, column=1, sticky="nsew")
datosEntry1 = Entry(labelframe1)
datosEntry1.grid(row=row1, column=1)
# COLUMN 3: TOTALES ===================
for row2 in range(3):
datosEntry2 = Label(labelframe1, text="Valor Total")
datosEntry2.grid(row=0, column=2, sticky="nsew")
datosEntry2 = Entry(labelframe1)
datosEntry2.grid(row=row2, column=2)
# total_parcial.append(datosEntry2)
# COLUMN 4: SUMINISTROS ===================
entries_suministros = {}
for row3 in range(3):
datosEntry3 = Label(labelframe1, text="Suministros")
datosEntry3.grid(row=0, column=3, sticky="nsew")
datosEntry3 = Entry(labelframe1)
datosEntry3.grid(row=row3, column=3)
entries_suministros["Entrybox{0}".format(row3)] = datosEntry3 # Entry
# COLUMN 5: MANO DE OBRA ===================
entries_mo = {}
for row4 in range(3):
datosEntry4 = Label(labelframe1, text="Mano de Obra")
datosEntry4.grid(row=0, column=4, sticky="nsew")
datosEntry4 = Entry(labelframe1)
datosEntry4.grid(row=row4, column=4)
entries_mo["Entrybox{0}".format(row4)] = datosEntry4 # Entry
###################################################################################
############ ============= BUTTON ================== ##########################
# BUTTON 1: =============================
calcular1 = Button(root, text="Send for Operations", command=GuardarDatos)
calcular1.pack()
root.mainloop()