我想使用 Python 3 中的 .format() 方法返回某个数值,并在其中使用 div 运算符 (/) 进行小型计算。
但是消息框库不支持此功能。
#Remind dilutions
if self.initial_concentration > (1000):
messagebox.INFO('Since your dilution is in the lowest range, consider a 1:100 pre-dilution first, so you would have {:2f}').format(answer)
你知道我怎样才能克服这个问题吗?
谢谢
最佳答案
messagebox.INFO('Since ... have {:2f}').format(answer)
# ^
# calling `format` method of the return value of the `INFO(..)`,
# (not against the formatting string)
# which may not exists; possibly causing AttributeError
上面一行应该替换为:
messagebox.INFO('Since ... have {:2f}'.format(answer))
关于python - tkinter messagebox 中的格式化方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42421747/