这是一个小例子和演示它有一切你需要启动你的程序。请参见代码内的注释:
import tkinter
app = tkinter.Tk()
# Create a set for all clicked buttons (set prevents duplication)
clicked = set()
# Create a tuple of words (your 180 verb goes here)
words = 'hello', 'world', 'foo', 'bar', 'baz', 'egg', 'spam', 'ham'
# Button creator function
def create_buttons( words ):
# Create a button for each word
for word in words:
# Add text and functionality to button and we are using a lambda
# anonymous function here, but you can create a normal 'def' function
# and pass it as 'command' argument
button = tkinter.Button( app,
text=word,
command=lambda w=word: clicked.add(w) )
# If you have 180 buttons, you should consider using the grid()
# layout instead of pack() but for simplicity I used this one for demo
button.pack()
# For demo purpose I binded the space bar, when ever
# you hit it, the app will print you out the 'clicked' set
app.bind('', lambda e: print( *clicked ))
# This call creates the buttons
create_buttons( words )
# Now we enter to event loop -> the program is running
app.mainloop()
编辑:
下面是不带lambda表达式的代码:
^{pr2}$