Home > Article > Backend Development > Why are My Tkinter Widgets Missing When I Store Them in an Array?
When creating Tkinter widgets and adding them to an array, it's crucial to understand that grid, pack, and place methods operate in-place and invariably return None. This means that attempting to store these widgets in an array on the same line as their creation will result in the array being filled with None values.
To resolve this issue, the creation of widgets and their placement methods should be executed on separate lines. The following demonstrates the correct approach:
<code class="python">widget = ... widget.grid(...) widget = ... widget.pack(...) widget = ... widget.place(...)</code>
In your code specifically, the following modifications are needed:
<code class="python">b[c+(r*10)] = Button(f, text=chr(97+c+(r*10)), command=lambda a=c+(r*10): color(a), borderwidth=1,width=5,bg="white") b[c+(r*10)].grid(row=r,column=c)</code>
The above is the detailed content of Why are My Tkinter Widgets Missing When I Store Them in an Array?. For more information, please follow other related articles on the PHP Chinese website!