我想通过一个参数传递给一个按钮,单击func并遇到问题。Python/ttk/tKinter - 用按钮单击func传递参数?
总之,我试图让按钮按下来弹出askColor()
方法,并返回该颜色值作为相关文本框的背景颜色。
它的功能是如此synaesthets可以将一个颜色与一个字母/数字关联并记录结果的颜色列表。
具体线路:
self.boxA = Text(self.mainframe, state='normal', width=3, height=1, wrap='word', background=self.AVal).grid(column=2, row=2, padx=4)
self.boxB = Text(self.mainframe, state='normal', width=3, height=1, wrap='word', background=self.AVal).grid(column=3, row=2, padx=4)
self.boxC = Text(self.mainframe, state='normal', width=3, height=1, wrap='word', background=self.AVal).grid(column=4, row=2, padx=4)
self.ABlob = ttk.Button(self.mainframe, text="A",style= 'mainSmall.TButton', command= lambda: self.getColour(self.boxA)).grid(column=2, row=3)
self.BBlob = ttk.Button(self.mainframe, text="B",style= 'mainSmall.TButton', command= lambda: self.getColour(self.boxB)).grid(column=3, row=3)
self.CBlob = ttk.Button(self.mainframe, text="C",style= 'mainSmall.TButton', command= lambda: self.getColour(self.boxC)).grid(column=4, row=3)
和:
def getColour(self,glyphRef):
(triple, hexstr) = askcolor()
if hexstr:
glyphRef.config(bg=hexstr)
的问题是,我似乎不能在我想的方式来引用self.ABlob
- 返回式None
。我试过在button click func中包含一个pack.forget
命令,但这也行不通。
我认为你是对的,我正在吠叫错误的树。删除了我的答案。 – tacaswell
啊!好。谢谢,我会看看这种方法,谢谢。 –
工作就像一个魅力,我学到了一些关于'嵌套'命令。欣赏它。感谢您的时间。 –