Valueerror: could not Convert string to float

Asked

Viewed 303 times

1

Hello I’m trying to make an application in Tkinter/python and I can’t get the code to return the result of the calculation. the code created is the following:

from tkinter import ttk
from tkinter import *

class Product:


    def click(self):
        l = float(self.larg.get())
        n = float(self.npeca.get())
        g = float(self.gram.get())
        print(c * l * g / n )



    def __init__(self, window):

        self.wind = window
        self.wind.title('SJ Texteis, SA')
        self.wind.geometry("550x150")
        self.wind.resizable(width=False, height=False)
        self.wind.iconbitmap("favicon.ico")



        frame = LabelFrame(self.wind, text='CALCULO CONSUMOS DE MALHAS')
        frame.grid(row=0, column=0, columnspan=10, pady=10, padx=25)

        Label(frame, text='Comp. do Plano: ').grid(row=1, column=0)
        self.comp = Entry(frame)
        self.comp.focus()
        self.comp.grid(row=1, column=1,)


        Label(frame, text='Largura da malha: ').grid(row=6, column=0)
        self.larg = Entry(frame)
        self.larg.grid(row=6, column=1)


        Label(frame, text= 'Nº de peças: ').grid(row=11, column=0)
        self.npeca = Entry(frame)
        self.npeca.grid(row=11, column=1)


        Label(frame, text='Gramagem: ').grid(row=16, column=0)
        self.gram = Entry(frame)
        self.gram.grid(row=16, column=1)



        ttk.Button(frame, text='Calcular Cons./peça', command=self.click).grid(row=25, column=2)

        self.cons = Entry(frame)
        self.cons.grid(row=25, column=7, padx=10, pady=5)







if __name__ == '__main__':
    window = Tk()

    application = Product(window)

    window.mainloop()

Where am I wrong?

  • Could post the entire error message in question?

  • 1

    Exception in Tkinter callback Traceback (Most recent call last): File "C: Users juliofaria Appdata Local Programs Python Python37-32 lib Tkinter_init_.py", line 1705, in call Return self.func(*args) File "C:/Users/juliofaria/Pycharmprojects/consumptions/index.py", line 8, in click l = float(self.larg.get()) Valueerror: could not Convert string to float:

  • Does not show the value he tried to convert to float at the end of this message?

  • Shows no more. Error appears when clicking the button.

  • And you get to report some value for the width of the mesh?

  • when testing with values, the following error appears:

  • I got it! missing var. c ( c = float(self.comp.get.())

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.