关于 tkinter 按钮的基本问题

编程入门 行业动态 更新时间:2024-10-25 18:31:30
本文介绍了关于 tkinter 按钮的基本问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我一般不熟悉使用 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 06:29:22,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1390797.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:按钮   tkinter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!