Home > Blockchain >  how to convert strings to float
how to convert strings to float

Time:12-17

code image

Hello, I am trying to write a code that takes in a number of inputs and outputs the graph that they form, (ex. quadratic equations, and cubic). In the image linked I am trying to get in the inputs as entrys from a window that I have created using Tkinter, however, when I go to work with the values I need to convert them into float numbers, however, I don’t know how I can it.

Can someone help me, please?

CodePudding user response:

here there is no function 'type' instead use 'delete' and 'insert' the '0' represents the cursor position (i.e in starting) and 'end' denotes till end

from tkinter import *
root=Tk() 
def conversion():
    global a
    global b
    global c
    global d
    for i in (a,b,c,d):
        k=float(i.get())
        i.delete(0,'end')
        i.insert(0,k)
a=Entry(root,text='3')
a. pack() 
b=Entry(root)
b.pack() 
c=Entry(root)
c.pack() 
d=Entry(root)
d.pack() 
buttonl=Button(root, text="press",command=conversion)
buttonl.pack() 
root .mainloop() 
  • Related