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.
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)