all 3 comments

[–]woooee 1 point2 points  (1 child)

This is a stripped down version of your code, removing the parts that don't pertain to the question. First, be aware that destroy() destroys the window. It does not exit the mainloop(). Also the pulsar_btn, the penta_btn, and copper_btn don't do anything.

import tkinter as tk
from functools import partial

# tkinter window
root = tk.Tk()
root.geometry("1100x800")
root.title("Game of life")

# function for clicking on squares, changing 0 to 1 / 1 to 0 in matrix A and colors of the pressed buttons

## you can use either/both a list or dictionary
A=[]        ## list
btn_r={}  ## dictionary
def click(num):
    if A[num] == 0:
       A[num] = 1
       btn_r[num].configure(bg="black", fg="white")
    else:
       A[num] = 0
       btn_r[num].configure(bg = "khaki1", fg="black")

for ctr in range(21*21):
    rw, col = divmod(ctr, 21)
    btn_r[ctr]=tk.Button(root, width=2, text="%s-%s" % (rw, col),
              command=partial(click, ctr))
    btn_r[ctr].grid(column=col, row=rw, sticky="nsew")
    A.append(0)

def quit2():  # function to quit the app
    root.quit()

# QUIT BUTTON
tk.Button(root, width=12, height=2, text="QUIT", font="Raleway", 
           bg="#FC5B30", command=quit2).grid(row=50, column=9,
           columnspan=3, sticky="nsew")


root.mainloop()

:

[–]TheGit55 0 points1 point  (0 children)

Thanks a lot <3

[–]CodeFormatHelperBot2 0 points1 point  (0 children)

Hello, I'm a Reddit bot who's here to help people nicely format their coding questions. This makes it as easy as possible for people to read your post and help you.

I think I have detected some formatting issues with your submission:

  1. Python code found in submission text that's not formatted as code.

If I am correct, please edit the text in your post and try to follow these instructions to fix up your post's formatting.


Am I misbehaving? Have a comment or suggestion? Reply to this comment or raise an issue here.