Use partial to send values to a function from a button command. And please don't get in the habit of using wildcard imports as you can't tell which variable or function comes from which name-space.
Use partial to send values to a function from a button command. And please don't get in the habit of using wildcard imports as you can't tell which variable or function comes from which name-space.
import sys if 3 == sys.version_info[0]: ## 3.X is default if dual system import tkinter as tk ## Python 3.x else: import Tkinter as tk ## Python 2.x from functools import partial result = [] def add_to_result(value): result.append(value) def clear_results(): result = [] def handler(value): print("letter =", value) add_to_result(value) root = tk.Tk() characters = 'abcdefghijklmnopqrstuvwxyz' for char in characters: btn = tk.Button(root, command=partial(handler, char)) photo = tk.PhotoImage(file="Symbols/{0}.png".format(char)) btn.config(image=photo) btn.pack()
Use partial to send values to a function from a button command. And please don't get in the habit of using wildcard imports as you can't tell which variable or function comes from which name-space.
import sys if 3 == sys.version_info[0]: ## 3.X is default if dual system import tkinter as tk ## Python 3.x else: import Tkinter as tk ## Python 2.x from functools import partial result = [] def add_to_result(value): result.append(value) def clear_results(): result = [] def handler(value): add_to_result(value) root = tk.Tk() characters = 'abcdefghijklmnopqrstuvwxyz' current_row=0 btn = tk.Button(root, text=char, width=10, command=partial(handler, char)) ## photo = tk.PhotoImage(file="Symbols/{0}.png".format(char)) ## btn.config(image=photo) btn.pack() root.mainloop()