0

Hi guys i'm making a Temperature Converter based on Tkinter in Python and it was all good but now i'm getting this error. I looked here on stackoverflow for this error, i found a lot of them but i couldn't figured out, so i'm here to post my code to see if you guys can help. The program crashes exactly when i click a option on the OptionMenu. (om_input specifically)

Here is the error:

Traceback (most recent call last):
TypeError: 'NoneType' object is not callable

It throws another exception:

AttributeError: 'StringVar' object has no attribute '_report_exception'

Here are snippets of my code:

This function is supposed to be called everytime the user selects an option in the OptionMenu in the GUI.

def check_entry():

if temperature_input.get() == "Celsius":
    celsius_converter(value_entry.get(), temperature_output.get(), output_entry)

elif temperature_input.get() == "Kelvin":
    kelvin_converter(value_entry.get(), temperature_output.get(), output_entry)

else:
    fahrenheit_converter(value_entry.get(), temperature_output.get(), output_entry)

The vars to be used with the OptionMenus

root = Tk()
temperature_list = ["Celsius", "Kelvin", "Fahrenheit"]    

temperature_input = StringVar(root)
temperature_input.set(temperature_list[0])

temperature_output = StringVar(root)
temperature_output.set(temperature_list[0])

output_entry = Entry(root, state=NORMAL)

Initialization of the OptionMenus

om_input = OptionMenu(root, temperature_input, *temperature_list, command=check_entry)
om_output = OptionMenu(root, temperature_output, *temperature_list, command=check_entry)
root.mainloop()
4
  • 2
    please provide a complete working program with the smallest amount of code that reproduces the problem (see stackoverflow.com/help/mcve) Commented Nov 30, 2015 at 21:14
  • Is that your entire traceback? I'd expect to see lines like File "myfile.py", line 9 and such before the actual error message. Did you cut anything out? Commented Nov 30, 2015 at 21:18
  • Well, while i was working on a minimal program, the program seemed to work, now i'm looking for whats different but i don't think anything is. I cut the parts i didn't think it was important for the problem. Commented Nov 30, 2015 at 21:55
  • I solved it. Just changed some things in a method. I'm new here, sorry for not posting correctly. Thanks for your time guys. Commented Nov 30, 2015 at 22:14

1 Answer 1

1

I solved it and the problem was in a method that i didn't post here, stupidly, and i apologize for that.

The method was like that:

def update_entry():
    temp_input.trace("w", check_entry())
    root.after(1, update_entry)

I went through Tkinter documentations and read about StringVar and the trace() method and i just changed "w" to "u", worked charmly. Thanks for your time.

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

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.