Search code examples
pythonpython-3.xtkintermessagebox

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(/).

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


Solution

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