2017-02-23 14 views
1

Python 3の.format()メソッドを使用して特定の数値を返したいのですが、その中にdiv演算子(/)を使った小さな計算をしたいと思います。tkinterメッセージボックスのフォーマットメソッド

ただし、メッセージボックスライブラリはこの機能をサポートしていません。

 #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機能は、あなたがINFOからではなく、STRからそれを使うべきです。

ソリューション:

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