Apr-22-2020, 03:42 AM
(This post was last modified: Apr-22-2020, 01:16 PM by deanhystad.)
Here is some code that makes 100 entry widgets organized in 5 columns and all of them bound so clicking Button-3 calls a function.
import tkinter as tk def button3_clicked(team, player, question, var): """This is a callback for a Button-3 event""" # Print out the team, player and question numbers as well as the answer. print(team, player, question, var.get()) def make_player(window, team, player): """I make 20 entries for a player""" boxes = [] for i in range(20): var = tk.IntVar() entry = tk.Entry(window, textvariable=var) var.set(i+player*100) # Set a value to verify button event works entry.grid(row=i, column=player) entry.bind('<Button-3>', \ lambda event, q= i: \ button3_clicked(team, player, q, var)) boxes.append(var) return boxes root = tk.Tk() team1 = [make_player(root, 0, 0), make_player(root, 0, 1), make_player(root, 0, 2), make_player(root, 0, 3), make_player(root, 0, 4)] tk.mainloop()If you right click inside a box it calls the button3_clicked function and prints out the value in the Entry box. I used an IntVar, but if you want these to contain strings it is easy enough to use a StringVar. Entry's are a lot easier to work with using a variable than trying to work directly with the widget.