python - tkinter messagebox 中的格式化方法

标签 python python-3.x tkinter messagebox

我想使用 Python 3 中的 .format() 方法返回某个数值,并在其中使用 div 运算符 (/) 进行小型计算。

但是消息框库不支持此功能。

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

你知道我怎样才能克服这个问题吗?

谢谢

最佳答案

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

关于python - tkinter messagebox 中的格式化方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42421747/

相关文章:

python - 索引错误 : index 201850347 is out of bounds for axis 0 with size 201837124 while using unstack operation for large dataset

python-3.x - 带有步进电机代码的运行时警告

Python 生成的 MySQL SELECT 查询不返回完整的结果列表

python - 动态 tkinter 输入框

python - 为什么 GridSearchCV 方法的精度低于标准方法?

python - 获取与 TensorFlow 中特定张量相关的所有 tf​​.Variables

python - 提取满足给定条件的单元格的列标签

python-3.x - 如果我有AMD显卡,如何使用tensorflow-gpu版本?

python - 为什么 `tkinter.ttk.Notebook`标签越来越薄?

python - Python使用别人文件时的缩进问题