3

This is my code:

from tkinter import *

def calculate():
    temp = int(entry.get())
    temp = 9/5*temp+32
    output_label.configure(text = 'Converted: {:.lf}'.format(temp))
    entry.delete(0,END)

root = Tk()
message_label = Label(text = 'Enter a temperature',
                     font=('Verdana', 16))
output_label = Label(font = ('Verdana', 16))
entry = Entry(font = ('Verdana', 16), width=4)
calc_button = Button(text ='ok', font=('Verdana', 16),
                    command=calculate)
message_label.grid(row=0, column=0)
entry.grid(row=0, column=1)
calc_button.grid(row=0, column=2)
output_label.grid(row=1, column=0, columnspan=3)

mainloop()

This is the output error:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\USER\Anaconda3\envs\nlp_course\lib\tkinter\__init__.py", line 1705, in __call__
    return self.func(*args)
  File "<ipython-input-9-c6af4eb59ca6>", line 7, in calculate
    output_label.configure(text = 'Converted: {:.lf}'.format(temp))
ValueError: Format specifier missing precision

Can someone help with this problem?

0

2 Answers 2

4

There is a small mistake in your format string:

'Converted: {:.lf}'

should be

'Converted: {:.1f}'

The only difference is that you have used l instead of 1 when specifying the float precision. 1f means that your float should be output with one decimal place.

Sign up to request clarification or add additional context in comments.

Comments

3

For me, this happened with

'Converted: {:.1.f}'

instead of the correct

'Converted: {:.1f}'

Probably happens when the format specifier is wrong

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.