0

I'm making a calculator program with Python. I want to output the sum of the numbers input using tkinter.

enter code here
def plus():
    e1.delete(0, END)
    e2.delete(0, END)
    e3.delete(0, END)
    x = int(e1.get()) #Inputed value.
    y = int(e2.get()) #Inputed value.
    return e3.insert(0, x+y)

e1 = Entry(window)
e2 = Entry(window)
e3 = Entry(window)
4
  • 1
    In your own words, if you remove all of the text from the e1 entry, and then try to convert the text that's there to an integer, what integer result do you think you should get? Why? In your own words, if you want to remove the text from the entry, and also convert the text that is currently there to an integer, then which of those two things should happen first? Why? Commented Dec 19, 2021 at 8:30
  • Welcome back to Stack Overflow. As a refresher, please read How to Ask and ericlippert.com/2014/03/05/how-to-debug-small-programs, and keep in mind that Stack Overflow should be treated as a last resort, after your best attempt to solve the problem yourself. If you get stuck, and have narrowed it down as best you can, you should at least make sure to ask an actual question, while explaining what you tried. Commented Dec 19, 2021 at 8:32
  • 1
    I am not being aggressive at all. I am focusing your attention on the aspects of the code that you need to consider, following the Socratic method. I am also informing you about Stack Overflow policy. Commented Dec 19, 2021 at 8:41
  • why is e3 an Entry? from the given code it doesn't seem that it would ever be used by the user, meaning it can simply be a read-only widget, such as Label Commented Dec 19, 2021 at 13:58

1 Answer 1

1

Why did you do this before you get()?

e1.delete(0, END)
e2.delete(0, END)

They go before e1.get() and e2.get(), so when you run e1.get(), it will return "". Then you should swap their order like this:

def plus():
    e3.delete(0, END)
    x = int(e1.get())
    y = int(e2.get())
    e1.delete(0, END)
    e2.delete(0, END)
    return e3.insert(0, x+y)

e1 = Entry(window)
e2 = Entry(window)
e3 = Entry(window)

This is my answer, thanks.

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.