问题描述
我是Tkinter的新手,单击时尝试创建一个“眉毛按钮”,选择一个图像,然后保存图像的路径,然后将图像的路径传递给另一个函数
我尝试了这个,但是得到了 function displayCountryName(value)
{
document.getElementById('countryName').value = value
}
我想将NameError: name 'MI' is not defined
(这是所选照片的路径)传递给MI
函数,您能帮我吗?
blur()
解决方法
虽然python正在执行代码并到达代码行
btnMask = Button(right,text='show',width=19,height=6,command=lambda: blur(MI))
在执行此行期间,它检查MI
但MI
不存在,并因此出错。只要MI
被python读取,就不会定义open_image()
。您不必传递MI
作为参数,将其设为open_image()
的全局变量应该可以在blur()
使用它。
btnMask = Button(right,command=blur)
.... #same code as yours
def blur():
I = cv.imread(MI)
I2 = cv.blur(I,3)
cv.imshow('dfdf1',I)
cv.waitKey()
如果您不传递任何参数,也可以安全删除lambda
。这样就可以使您的按钮:
btnBrowse = Button(top,width=93,text='select file',font=('Times',15,'italic','bold'),command=open_image)
btnMask = Button(right,command=blur)
因此,基本上,您的错误与对代码流向的误解有关。
不确定这是否可以解决您的所有错误。让我知道这是否有效。
,如果<small id="foo">This text should be in your clipboard after clicking the copy button</small>
<br />
<button id="bar" type="button">copy</button>
<br />
<textarea placeholder="try pasting here after clicking copy button" cols="60" rows="3"></textarea>
是全局的,请尝试使用:
MI
和:
btnMask = Button(right,command=lambda: blur())
不带 def blur():
....