App 5: Desktop App with Windows & Buttons / Build a calculator
Lesson 4 of 10
Making buttons work
press() adds the character to the entry, or calculates when '=' is pressed. We'll do the maths safely without eval.
Key points
- entry.insert(tk.END, ch) adds text
- entry.get() reads it
- entry.delete(0, tk.END) clears it
def press(ch):
if ch == "=":
calculate()
else:
entry.insert(tk.END, ch)Your turn
Write press() so number buttons type into the entry.
Quiz · +10 XP
Which method reads the text inside an Entry?
Log in to save progress and earn XP.