I'm working with Tkinter and I need to make 600 buttons in a grid of 6x100. Is there a way to produce generic variables by going through a for loop? Or do I have to type all 600?
Destray 0 Newbie Poster
Recommended Answers
Jump to PostYou don't have to type all 600 ! What code would you type to create only one ?
Jump to PostI suggest a button array
buttonlist = [] for i in range(600): buttonlist.append(Button(frame, *various_options))
Also, to change the image, i suggest something like
button.config(image=...)
but I normally don't use tkinter, so I'm not sure. This link may help.
Jump to PostThe same code with a call back to show which button was pressed. Hopefully you will use a class structure for this as that eliminates shared variable problems.
from Tkinter import* def cb_handler(event, cb_number ): print "cb_handler - button number pressed =", cb_number root = Tk() frame …
All 9 Replies
Gribouillis 1,391 Programming Explorer Team Colleague
Destray 0 Newbie Poster
Gribouillis 1,391 Programming Explorer Team Colleague
Destray 0 Newbie Poster
Gribouillis 1,391 Programming Explorer Team Colleague
Destray 0 Newbie Poster
woooee 814 Nearly a Posting Maven
Gribouillis 1,391 Programming Explorer Team Colleague
Destray 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.