【发布时间】:2013-01-13 05:57:52
【问题描述】:
我正在尝试将参数传递给按钮单击函数并遇到问题。
简而言之,我试图按下按钮以弹出askColor() 方法,并将该颜色值作为相关文本框的背景颜色返回。
它的功能是使联觉者可以将颜色与字母/数字相关联并记录生成的颜色列表。
具体行:
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。我尝试在按钮单击功能中包含pack.forget 命令,但这也不起作用。
【问题讨论】: