2017-02-23 4 views
1

Ich möchte einen bestimmten numerischen Wert mit der .format() -Methode in Python 3 zusammen mit einer kleinen Berechnung in ihm mit dem Div-Operator (/) zurückgeben.Format Methode in tkinter messagebox

Die MessageBox-Bibliotheken unterstützen diese Funktion jedoch nicht.

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

Wissen Sie, wie kann ich das überwinden?

Danke

Antwort

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 

Above Linie ersetzt werden sollte:

es aus dem str
messagebox.INFO('Since ... have {:2f}'.format(answer)) 
2

format ist eine Funktion str stattdessen von der INFO verwenden, sollten Sie.

Lösung:

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