Reputation: 9521
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 ?
Upvotes: 4
Views: 177
Reputation: 385970
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.
Upvotes: 2