2017-02-23 43 views
1

我想使用Python 3中的.format()方法返回一个特定的数值,并在其中使用div运算符(/)在其中进行小计算。tkinter messagebox中的格式化方法

但是,messagebox库不支持此功能。

 #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) 

你知道我该怎么克服这个问题?

谢谢

回答

2
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)) 
2

format是STR功能,你应该从STR用它代替从INFO。

解决方案:

messagebox.INFO('Since your dilution is in the lowest range, consider a 1:100 pre-dilution first, so you would have {:2f}'.format(answer))