Home
Categories
WIKI
Topic
User
LANGUAGE:
中文
English
ValueError: could not convert string to float:
Apps Section
2264
views ·
0
replies ·
To
floor
Go
gentoo
deepin
2013-04-14 22:40
Author
from Tkinter import *
from ast import *
function = lambda x : x ** 2
class App:
def areaPiece(self,mark,step):
lengthUp = function(mark)
lengthDown = function(mark + step)
height = step
area = (lengthUp + lengthDown) * height / 2
def calculator(self,x,x0):
y = function(x)
y0 = function(x0)
y1 = y - y0
area0 = 0
mark0 = 0
step = x / 10000
while mark0 < x0:
area0 += areaPiece(mark0,step)
mark0 += step
mark1 = x0
areaRight = 0
while mark1 < x:
areaRight += areaPiece(mark1,step)
mark1 += step
areaAllRight = (x - x0) * y
area1 = areaAllRight - areaRight
delta = area0 * y1 + area1 * y0
def callback(self):
delta = calculator(x,x0)
Rstring.set(delta)
return area
def __init__(self,master):
Xlabel = Label(master,
text = "please input x:")
Xlabel.pack(side = LEFT)
Xtext = StringVar()
Xentry = Entry(master,
textvariable = Xtext)
Xentry.pack(side = LEFT)
X0label = Label(master,
text = "please input x0:")
X0label.pack(side = LEFT)
X0entry = Entry(master)
X0entry.pack(side = LEFT)
Rstring = StringVar()
Rlabel = Label(master,
textvariable = Rstring)
Rstring.set('RESULT')
Rlabel.pack(side = LEFT)
x = float(Xtext.get())
#x0 = int(X0entry['text'])
#x = literal_eval(Xentry.get())
#x0 = literal_eval(X0entry)
calButton = Button(master,
command = lambda:self.calculator(x,x0),
text = "CAL")
calButton.pack()
#calButton.bind('',lambda :callback())
mainWin = Tk()
app = App(mainWin)
mainWin.mainloop()
Copy the Code
怎么样才能将文本框中的字符串转换成浮点型数字进行计算??
Reply
Like 0
Favorite
View the author
All Replies
No replies yet
Please
sign
in first
Featured Collection
Change
UOS AI 2.8 Released! Three New Intelligent Agents & Major Evolution
Solid Q&A | deepin 25 Common Questions – The Immutable System Edition
New Thread
Popular Ranking
Change
Display errors in control center translations
Popular Events
More
怎么样才能将文本框中的字符串转换成浮点型数字进行计算??