【发布时间】:2017-01-09 05:01:12
【问题描述】:
我正在尝试在 Tkinter (Python) 中编写一个开始/暂停按钮,但以下代码不起作用:
def startpause():
if startpause_button.cget('image')=='start_image':
startpause_button.config(image=pause_image)
else:
startpause_button.config(image=start_image)
return
start_image=ImageTk.PhotoImage(file='start.png')
pause_image=ImageTk.PhotoImage(file='pause.png')
startpause_button=ttk.Button(frame,image=start_image,command = startpause)
我知道问题是关于 cget(它返回 ('pyimage3'), )以及它返回的内容,但我不知道应该将什么作为值来检查 ("('pyimage3')," 不工作)。
你对这个问题有什么想法吗?
谢谢。
【问题讨论】:
-
尝试将其与您的
start_image进行比较,而不是字符串'start_image'