在tkinter中单击按钮后,一种返回按钮文本的方法

在tkinter中单击按钮后,一种返回按钮文本的方法,第1张

在tkinter中单击按钮后,一种返回按钮文本的方法

试图在lambda中完成所有这些 *** 作是错误的方法。简直太令人困惑了,即使不是不可能做您想做的事情。而是创建一个可以完成工作的方法,并仅将lambda用作调用该函数的一种方式:

from Tkinter import *class GraphicsInterface:    def __init__(self):        self.window = Tk()        self.window.geometry("720x500")        self.clicked=[]        button1 = Button(self.window, text="Dice 1", width=13)        button2 = Button(self.window, text="Dice 2", width=13)        button1.pack()        button2.pack()        button1.configure(command=lambda btn=button1: self.onClick(btn))        button2.configure(command=lambda btn=button2: self.onClick(btn))        self.window.mainloop()    def onClick(self, btn):        text = btn.cget("text")        self.clicked.append(text)        print "clicked:", self.clickedapp = GraphicsInterface()


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5639623.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-16
下一篇2022-12-16

发表评论

登录后才能评论

评论列表(0条)

    保存