简体   繁体   English

Tkinter消息框中的格式化方法

[英]Format method in tkinter messagebox

I would like to return a certain numeric value using the .format() method in Python 3, together with a small calculation in it with the div operator(/). 我想使用Python 3中的.format()方法返回某个数值,并使用div运算符(/)在其中进行少量计算。

However the messagebox libraries do not support this feature. 但是,消息框库不支持此功能。

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

Do you know how can I overcome this? 你知道我该如何克服吗?

Thank you 谢谢

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 line should be replaced with: 上面的行应替换为:

messagebox.INFO('Since ... have {:2f}'.format(answer))

format is an str function, you should use it from the str instead from the INFO. format是一个str函数,您应该从str中使用它而不是从INFO中使用它。

Solution: 解:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM