我正在尝试编写一些代码,用目录中的文件名(.png图像)填充spinbox。然后在Spinnerbox中选择一个项目显示图像。我有从纺纱器传递值用GETTkinter Spinbox在命令函数中使用获取值
产生的误差问题是:
photo = PhotoImage(file=XS_Spinbox.get())
AttributeError: 'NoneType' object has no attribute 'get'
注意到硬编码的文件名工程...
photo = PhotoImage(file='Arm_DEM_192_XSplot.png')
。
XS_Spinbox = Spinbox(myframe2, values = ([x for x in os.listdir(os.curdir) if os.path.splitext(x)[1] in ('.png')]), command=update_photoImage).pack()
def update_photoImage():
#print XS_spinBox.get()
#photo = PhotoImage(file=XS_spinBox.get())
photo = PhotoImage(file=XS_Spinbox.get())
label.image = photo
return
我认为这个问题是更多的Tkinter部件纺纱器如何传递值命令的功能呢? –
DEF update_photoImage(): 打印XS_Spinbox.get() 相片=光象(文件= XS_Spinbox.get()) 相片= photo.subsample(2,2) #label =标签(myframe2,图像照片=) label.configure(image = photo) label.image = photo print'Image updated ...' return使用spinbox.get数据成功更新图像 –