【问题标题】:Generate unique button using for loop tkinter使用 for loop tkinter 生成唯一按钮
【发布时间】:2020-01-14 18:50:07
【问题描述】:

我使用 for 循环创建了一个成功的按钮,但我无法将不同的参数传递给函数 或者 有什么方法可以为按钮分配 id 或 name 然后获取名称

【问题讨论】:

    标签: python button tkinter unique


    【解决方案1】:

    如果不是,我需要更多信息,但听起来你想做的事情可以用回调函数来处理。来自effbot tkinter pages:

    def callback(number):
        print "button", number
    
    Button(text="one",   command=callback(1)).pack()
    Button(text="two",   command=callback(2)).pack()
    Button(text="three", command=callback(3)).pack()
    

    而不是 1、2、3,只需插入您需要的任何回调 ID/信息。

    【讨论】:

    • 但我使用 for 循环来生成数字
    猜你喜欢
    • 2022-08-19
    • 1970-01-01
    • 1970-01-01
    • 2022-06-17
    • 2011-05-13
    • 2018-11-27
    • 2020-06-21
    • 2017-11-20
    • 1970-01-01
    相关资源
    最近更新 更多