Here's a simple GUI program that creates a 5x16 matrix of buttons.
from tkinter import *
root = Tk()
button = [[0 for x in range(16)] for x in range(5)]
for r in range(5):
for c in range(16):
button[r][c] = Button(root, bg='red')
button[r][c].grid(row=r, column=c)
root.mainloop()
Now when I run this program on my relatively OK Ubuntu Laptop (Ram 4 GB, quad core Intel Pentium(R) CPU N3540 @ 2.16GHz × 4, 64 bit),
The buttons appear visibly slowly, one after another as shown in this gif:

Is asking to draw 80 buttons too much of an asking for Tkinter to handle without this sluggishness ?
Or can my code be refactored for better performance ?
If the code in your question is literally all there is, there must be something wrong with your system. This should appear nearly instantaneously.
And no, there's no way to refactor for better performance. If you need a grid of 80 buttons, the way you're doing it is just about as efficient as you can make it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With