2017-02-23 42 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))