3

I'm trying to create Conway's Game of Life in python3 using . 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")
Nae
  • 14,209
  • 7
  • 52
  • 79
ggkfox
  • 141
  • 1
  • 8
  • 1
    Why do you need Frames? They are very expensive to create and maintain and absolutely unnecessary in your case. Just draw a bunch of vertical and horizontal lines on the canvas. – DYZ Feb 13 '18 at 00:24
  • i was using frames so that i can set background colors for individual tiles, which occurs later on. – ggkfox Feb 13 '18 at 00:29
  • 4
    Then you should use rectangles on the canvas. – DYZ Feb 13 '18 at 00:40
  • What platform are you running on? I'm guessing OSX. – Bryan Oakley Feb 13 '18 at 02:00
  • no im using linux. – ggkfox Feb 13 '18 at 08:44
  • The simple answer to your side question is to use one of the collection types instead of overwriting the same variable and simply populate them. – Nae Feb 13 '18 at 10:55
  • @nae rather than changing the colors of every square, i discovered the canvas.delete("all") function, then i just repopulate with the same module. i finished my Game of Life project, but ill google what collection types are. thank you Nae. – ggkfox Feb 15 '18 at 23:51
  • @ggkfox I mean like `list`, `dict`, `tuple` etc. – Nae Feb 16 '18 at 08:28

1 Answers1

2

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.

Nae
  • 14,209
  • 7
  • 52
  • 79
ggkfox
  • 141
  • 1
  • 8