Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6857813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:04:38+00:00 2026-05-27T02:04:38+00:00

new guy here and I’m slowly getting the hang of python, but I have

  • 0

new guy here and I’m slowly getting the hang of python, but I have a question.

I have two files here

one is named first_file.py

from other_file import GameFrame
from Tkinter import Tk

def main():
    tk = Tk()
    tk.title("Game of Life Simulator")
    tk.geometry("380x580")
    GameFrame(tk)
    tk.mainloop()
main()

and the other is other_file.py

from Tkinter import *
from tkFileDialog import *

class GameFrame (Frame):
    def __init__(self, root):
        Frame.__init__(self,root)
        self.grid()
        self.mychosenattribute=8 
        self.create_widgets()

    def create_widgets(self):
        for rows in range(1,21):
            for columns in range(1,21):
                self.columns = columns
                self.rows = rows
                self.cell = Button(self, text='X')
                self.cell.bind("<Button-1>", self.toggle)
                self.cell.grid(row=self.rows, column=self.columns)

    reset = Button(self, text="Reset")
    reset.bind("<Button-1>", self.reset_button)
    reset.grid(row=22, column = 3, columnspan=5)

    def reset_button(self, event):
        self.cell.destroy()
        for rows in range(1,21):
               for columns in range(1,21):
                   self.columns = columns
                   self.rows = rows
                   self.cell = Button(self, text='')
                   self.cell.bind("<Button-1>", self.toggle)
                   self.cell.grid(row=self.rows, column=self.columns)

After I push the reset button what happens right now is one button gets destroyed and another set of buttons are made on top of the already present buttons, but I need to be able to destroy or atleast configure all buttons to be blank. So how would I do that for all the buttons since I used a for loop to generate them? (Is there a better way to generate the buttons besides using a for loop?) Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:04:39+00:00Added an answer on May 27, 2026 at 2:04 am

    A common method is to save your objects in a list (or dictionary) in order to access them when needed. A simple example:

    self.mybuttons = defaultdict(list)
    for rows in range(1,21):
        for columns in range(1,21):
            self.mybuttons[rows].append(Button(self, text=''))
    

    Then you can get buttons, this way:

    abutton = self.mybuttons[arow][acolumn]
    

    There are some problems with your code that prevent running it (indentation of the reset lines and the use of the undefined self.toggle), so I could not fix it, but this example should be enough for you to do it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm a new Ruby/Rails guy. Here's one question puzzling me: Can we find the
I have never developed for WAMP, the hosting guy for my new client says
Here is my scenario. I'm am HTML/CSS guy, JavaScript not so much. But this
I'm a VB guy learning C#. I seem to be getting the hang of
Hey everyone, a new guy here in C#.Net. I'm trying to make an application
I have a similar problem to this guy: Importing/Exporting Project Preferences , but my
new guy here! I am building a custom shopping cart driven by mysql and
New guy here so bear with me. Ive got a basic XSL file that
i am a totally new guy around here and i dont know whether its
So I am an old web forms guy and new to the MVC (in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.