0

I've made a simple calculator using tkinter. When the window launches, the responsiveness of the buttons is sporadic. Sometimes clicking them works, other times it doesn't. However, after I manually resize or move the window the buttons always work.

Video of the issue

Here's the general layout of my code:

from tkinter import *

def button_click(number):
    current = e.get()
    e.delete(0, END)
    e.insert(0, str(current) + str(number))

root = Tk()
root.title("Simple Calculator")

e = Entry(root, width=45, borderwidth=5)
e.grid(row=0, column=0, columnspan=3, padx=10, pady=10)

button_1 = Button(root, text="1", command=lambda: button_click(1))
button_1.grid(row=1, column=0)
button_2 = Button(root, text="2", command=lambda: button_click(2))
button_2.grid(row=1, column=1)

root.mainloop()

I first tried to resolve this by force updating the GUI:

root.update_idletasks()

This did not work. Next I tried programatically resizing the window:

root.geometry('1x1')
root.geometry('')

I also tried delaying the main loop:

root.after(100, root.mainloop)
2
  • 4
    "It is mentioned in few questions on SO that the built-in version of Python in certain MacOS is broken. Try reinstalling Python from python.org. – acw1668 Nov 13 at 10:29 " stackoverflow.com/questions/77472883/… Commented Dec 12, 2023 at 16:36
  • I have an answer which outlines the steps for installing/updating/replacing tkinter on Mac OS, if that helps! Commented Dec 12, 2023 at 18:05

0

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.