[Tkinter-discuss] New member howdy And is there a better way to use Buttons ?
jmcmonagle at velseis.com.au
Thu Jun 12 08:33:13 CEST 2008
John Edens wrote:
> Hi all, I’ve just started working with Python and Tkinter.
> One of the things I think I’ve noted is that Button commands do not pass
> Is there a way around this?
The short answer is... use a lambda or a named function.
> And is there a better way to code the following:
> I’ve written a small application that puts a Label in row 0 of a Frame
> and puts 26 buttons labeled A – Z in the second row.
> When the user clicks on a button, the associated letter is displayed in
> the label.
# Creates a label in row 0
# Creates 26 buttons A - Z in row 2
# Clicking a button changes the displayed label
from Tkinter import *
self.tv = StringVar()
self.lText = Label(master, textvariable = self.tv)
self.lText.grid(row = 0, columnspan = 26)
col = 0
for letter in string.uppercase:
Button(master, text=letter, command=lambda input=letter:
col += 1
root = Tk()
app = Application(root)
More information about the Tkinter-discuss