【发布时间】:2017-02-06 04:31:18
【问题描述】:
我正在尝试编写一些代码,用目录中的文件名(.png 图像)填充旋转框。然后在旋转框中选择一项显示图像。我无法使用 get 从 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 小部件 spinbox 如何将值传递给命令函数?
-
def update_photoImage(): print XS_Spinbox.get() photo = PhotoImage(file = XS_Spinbox.get()) photo = photo.subsample(2,2) #label = Label(myframe2, image= photo) label.configure(image = photo) label.image = photo print 'Image updated ...' return 这成功使用 spinbox.get data 更新图像