python用户登录d_创建依赖于输入的按钮,获取用户d

这是一个小例子和演示它有一切你需要启动你的程序。请参见代码内的注释:

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}$

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值