关于 tkinter 按钮的基本问题 [英] basic question about tkinter buttons

查看:33
本文介绍了关于 tkinter 按钮的基本问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一般不熟悉使用 tkinter 和 GUI 编程,所以这可能是一个非常基本的问题.无论如何,假设我有一组按钮供用户选择,我想要的是用户单击的所有按钮对象的列表.基本上,我想知道用户点击了哪些按钮.

I'm new to using tkinter and GUI programming in general so this may be a pretty basic question. Anyway, suppose I have a set of buttons for the user to choose from and what I want is a list of all the button objects that were clicked by the user. Basically, I want to know which buttons the user clicked.

推荐答案

在每个按钮上,您可以设置命令以将它们自己添加到单击的按钮列表中.

On each of the buttons you could set the command to add themselves to a list of clicked buttons.

clicked = []
foo = Button(root, text='bar', command=lambda self:clicked.append(self))

不确定语法是否全部正确,但这是基本思想.

Not sure if the syntax is all correct, but that's the basic idea.

这篇关于关于 tkinter 按钮的基本问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆