Help Receive data from tkinter gui and perform mathematical operations between lists

0 votes

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?

  1. 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".

  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()

Nov 4, 2020 in Python by Jessica
• 120 points
910 views

Hey, @Jessica

Did you face any error while executing your code?

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Python

0 votes
1 answer

Difference between del, remove and pop on lists

es, remove removes the first matching value, ...READ MORE

answered Aug 1, 2018 in Python by Priyaj
• 58,100 points
979 views
0 votes
1 answer

difference between lists and sets

There are a lot more differences such ...READ MORE

answered Jan 7, 2019 in Python by SDeb
• 13,300 points
756 views
0 votes
5 answers
0 votes
1 answer
0 votes
0 answers

What is the difference between import module and from module import?

When both serves the same purpose, why ...READ MORE

May 22, 2019 in Python by Waseem
• 4,540 points
1,556 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,350 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP