LeroyJD LeroyJD - 7 months ago 20
Python Question

Tkinter Grid Manager (TypeError)

I'm trying to put a set of 16 pictures into a tkinter frame. I've created a dictionary that maps the image address name (stored in imgbutton) as a key to the dictionary imagedict the value of which is a string containing its position in the tkinter grid (example a button in column 0 and row=1 would have the name backgroundpic5.jpg and the value "01").

Each row contains 4 pictures and there are 4 rows in total. The PhotoImage equivalent of imgbutton is buttonphoto (created using PIL). However, when i try running this, it tells me the grid_configure command accepts on 2 arguments while i have given 3 (Type Error)

Pos=imagedict[imgbutton]
GridColumn=Pos[0]; GridRow=Pos[1]
Button= tk.Button(root, image=buttonphoto)
Button.grid(GridColumn, GridRow)
Button.pack()


The error statement,

Traceback (most recent call last):
File "C:\Users\USER\Desktop\ComputerProject\Tester2Imagebg.py", line 44, in <module>
Button.grid(GridColumn, GridRow)
TypeError: grid_configure() takes at most 2 arguments (3 given)


Thanks :)

Answer

Try doing the following.

 Pos=imagedict[imgbutton]
 GridColumn= Pos[0]; GridRow= Pos[1]
 Button= tk.Button(root, image=buttonphoto)
 Button.grid(column=GridColumn, row=GridRow)
 Button.pack()