简体   繁体   English

如何计算用户使用 tkinter 输入的 2 个值的百分比

[英]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.

相关问题 如何计算 pandas dataframe 中空值的百分比? - How can I calculate the percentage of empty values in a pandas dataframe? 如何在 tkinter ENTRY 中突出显示预先输入的文本,以便用户只需输入(无需选择、删除) - How can I highlight the pre-entered text in tkinter ENTRY so User can just type over ( without selecting, deleting) 如何计算缺失值的百分比 - How to calculate percentage of missing values 如何使用 python 计算值列表中的百分比增加或减少 - How do i calculate the percentage increase or decrease in a list of values with python 当用户继续在TKinter中更改值(使用跟踪方法)时,使用Entry并更新输入的条目 - Using Entry and updating an entry entered, as the user continues to change the values (using trace method) in TKinter 我可以用groupy和pandas计算百分比吗 - Hou can i calculate percentage using groupy with pandas 我如何计算输入字符串的平均长度 - how can i calculate the average length of the strings entered 如何计算 groupby 列的百分比并按降序排序? - How can I calculate percentage of a groupby column and sort it by descending order? 如何计算每行中每个值的百分比? - How can I calculate the percentage of each value in every row? 如何计算开始期间的累积百分比变化 - How can I calculate cumulative percentage change from beginning period
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM