0

i am creating a simple calculator in python. when i click button 1 i need to display on the display textbox 1.

enter image description here

but nothing displayed what i tried so far i attached below.

Button code

Button(root, text="1", command=b1, height=2, width=8).place(x=10, y=150)

click the button It will goes to the method b1

def b1():
   
    e1.get() == e1.get() + "1";

Textbox Code

e1 = Entry(root)
e1.place(x=10, y=80, height=50, width=300, )

what is the problem

tutusfun
  • 39
  • 9
  • 1
    I guess e1 is where you display the calcul (providing more code could be useful for us to understand). `e1.get()` just return the value of this element, you can't set its value like this, it's probably `e1.setValue(newvalue)` or `e1.value = newvalue`, plus `==` is only for comparison, not value assignment – Marius ROBERT May 19 '22 at 08:07
  • 1
    e1 is a textbox i update the full code now – tutusfun May 19 '22 at 08:11
  • 1
    e1.get() == e1.get() + "1"; so how to write this line i wrote e1.setValue("1") but not working please help me write – tutusfun May 19 '22 at 08:12
  • I don't remember the exact syntax, maybe `e1.text += "1"` but I'm not sure, read the doc for full explanation – Marius ROBERT May 19 '22 at 08:19
  • i tried i got the error e1.text += "1" AttributeError: 'Entry' object has no attribute 'text' – tutusfun May 19 '22 at 08:21
  • i checked but i couln't find the answer – tutusfun May 19 '22 at 08:27
  • Check again, these are literally the first links I found : [first](https://stackoverflow.com/questions/16373887/how-to-set-the-text-value-content-of-an-entry-widget-using-a-button-in-tkinter), [second](https://www.delftstack.com/howto/python-tkinter/how-to-set-text-of-tkinter-entry-widget-by-using-a-button/), [third](https://stackhowto.com/how-to-set-default-tkinter-entry-value-in-python/) – Marius ROBERT May 19 '22 at 08:30
  • pad1 = e1.get() pad1 = pad1 + "1" e1.set(pad1) – tutusfun May 19 '22 at 09:07
  • i tried but not working – tutusfun May 19 '22 at 09:07

0 Answers0