Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using grid with frames is very slow

Tags:

python

tkinter

I'm trying to create Conway's Game of Life in python3 using tkinter. I am attempting to initialize all the tiles (like a chessboard for those who don't know of the game of life). The grid is displaying correctly, however, it is way too slow (it takes about 4 or 5 seconds). Here is my code:

for i in range(h):
    for j in range(w):
        tile = Frame(root, width=30, height=30, bg="#000")
        tile.grid(row=i, column=j, padx=1, pady=1)

note: h and w values (dictate how many pixels the tiles are wide and tall) aren't very large at all. only like 20x30.

I have found a similar question here, but it sounds like the number of iterations is vastly different:

tkinter is very slow - how to speed it up or use a different library?

Is there something wrong with my implementation or should I resort to an alternate library?

SIDE QUESTION: also with all my tiles named the same exact thing, I'm not sure how to select a single one in order to change its background color.

tile.config(background = "#FFFFFF")
like image 576
ggkfox Avatar asked Feb 24 '26 18:02

ggkfox


1 Answers

DyZ hit the nail on the head. Frames were slow and Rectangles were much easier. I just thought I put it in a much easier to read location.

like image 105
ggkfox Avatar answered Feb 26 '26 07:02

ggkfox



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!