[英]how can I calculate the percentage of 2 values an user entered using tkinter
I have to do a little program, I have to calculate the percentage of savings a user has using the information the user provides.我必须做一个小程序,我必须使用用户提供的信息来计算用户节省的百分比。 So this is my code
所以这是我的代码
savings_box = tk.Entry(new_goal_window, width=75)
savings_box.place(x=450,y=150)
goal_total = tk.Entry(new_goal_window, width=75)
goal_total.place(x=450,y=350)
What I need to do is, with the data the user entries, I have to calculate the percentage, however I am not able to convert the entries to a numeric value, I can only have strings instead of integers or floats, and I cannot do a thing with that, what should I do?我需要做的是,使用用户输入的数据,我必须计算百分比,但是我无法将条目转换为数值,我只能有字符串而不是整数或浮点数,我做不到有这样的事,我该怎么办?
Convert the values from strings to floats:将值从字符串转换为浮点数:
percentage = (float(savings_box.get()) / float(goal_total.get())) * 100
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.