My question relates to tkinter. I am creating a GUI in which there are 31 different buttons with a different logo on each button. Here is how I create those buttons in the main window:
logos = ['ducks.png', 'bruins.png', 'sabres.png', 'flames.png', 'canes.png', 'hawks.png', 'avs.png',
'jackets.png', 'stars.png', 'redwings.png', 'oilers.png', 'panthers.png', 'kings.png',
'wild.png', 'habs.png', 'preds.png', 'devils.png', 'isles.png', 'rangers.png', 'sens.png',
'flyers.png', 'yotes.png', 'pens.png', 'blues.png', 'sharks.png', 'bolts.png', 'leafs.png',
'canucks.png', 'knights.png', 'caps.png', 'jets.png']
for logo in logos:
load = Image.open(logo)
render = ImageTk.PhotoImage(load)
teamButton = Button(self, image=render)
teamButton.image = render
teamButton.place(x=x_axis, y=y_axis)
x_axis += 80
if x_axis >= 300:
y_axis += 55
x_axis = 0
What I am trying to do:
- When user clicks certain button for example "ducks" the program prints a value, let's say 3.
- Then, when user clicks another button for example "Bruins" the program prints value 2.
My questions are:
- How do I bind the button Ducks with value 3 and the button Bruins with value
- And is this the best way (
for
loop) to create these type of buttons? If it's not, what is?