Python更改按钮图像并将其更改为b

2024-04-25 06:36:13 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我有一些代码可以在点击时改变按钮的图像。现在,如果我只想让按钮在被点击时改变,然后恢复正常呢?(就像普通按钮一样)我不能只添加另一个.config方法,因为它会跳过第一个方法,并保持按钮的图像不变。我也不能等待,因为它只是冻结程序并产生相同的结果。在

PlayUp = PhotoImage(file=currentdir+'\Up_image.gif')
PlayDown = PhotoImage(file=currentdir+'\Down_image.gif')
#Functions
def playButton():
    pButton.config(image=PlayDown)
    return

#Play Button
pButton = Button(root, text="Play", command=playButton)
pButton.grid(row=1)
pButton.config(image=PlayUp)

Tags: 方法图像imageconfigplaybuttongif按钮
1条回答
网友
1楼 · 发布于 2024-04-25 06:36:13

最好的方法,使按钮图像改变为看起来像一个真正的按钮按下,但图像是这样做的。在

定义您的照片:

PlayUp = PhotoImage(file=currentdir+r'\Up_image.gif')
PlayDown = PhotoImage(file=currentdir+r'\Down_image.gif')

定义您的功能:

^{pr2}$

初始化按钮:

#Play Button
pButton = Button(root, text="Play", command=playButton, borderwidth=0)
pButton.grid(row=1)
pButton.config(image=PlayUp)

相关问题 更多 >