【问题标题】:Tkinter buttons with images not appearing没有出现图像的 Tkinter 按钮
【发布时间】:2020-11-30 02:43:08
【问题描述】:

所以,我试图用 python 和 tkinter 制作音乐播放器,我必须为按钮设置图像,但是当我为按钮设置图像时,按钮不会出现在输出屏幕上

代码:

from tkinter import *
import pygame
win = Tk()
win.title("Music player")
win.geometry("500x300")

# Images for buttons
back_png = PhotoImage("C:/1 Files and Folders/SHARAN/Python/SVE atom/Images/back.png")
back_button = Button(win, image=back_png, borderwidth=0).place(x=100, y=20)


win.mainloop()

【问题讨论】:

    标签: python tkinter button


    【解决方案1】:

    tkinter 大多数参数都需要一个关键字。在这里,您缺少 file= 关键字。

    back_png = PhotoImage(file="C:/1 Files and Folders/SHARAN/Python/SVE atom/Images/back.png")
    

    【讨论】:

    • 嗯对我有用......我测试了它。还是同样的问题?你有错误吗?描述问题所在。
    • 没有错误,输出屏幕出现但没有按钮,或者按钮非常小
    • 嘿,我能够修复,这不是我的代码的问题,我的 IDE 忽略了 PhotoImages
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-08-20
    • 2012-04-20
    • 2012-06-10
    • 2017-01-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多