【问题标题】:Tkinter custom background image [duplicate]Tkinter自定义背景图像[重复]
【发布时间】:2016-12-18 12:18:47
【问题描述】:

我想将自定义图像作为整个应用背景。 我在某处读到我必须这样做:

root = Tk()
bg_image = PhotoImage(file="C:/Users/Matteo/Desktop/fisica.png")
app = App(root,image=bg_image)
root.title("Fisica")
root.geometry("330x470")
root.mainloop()

当我尝试运行代码时,它说:
TypeError: init() 得到了一个意外的关键字参数 'image'

我不明白是什么问题

【问题讨论】:

    标签: python tkinter


    【解决方案1】:

    您应该将图像添加到标签:

     Label(root, image=bg_image)
    

    然后使用.pack().grid() 将标签定位到网格。

    看这里:

    how to put a image as a background in tkinter in python

    您可以通过搜索 stackoverflow/google 找到此内容。

    您不能将图像直接添加到根窗口。

    【讨论】:

    • 所以不能做类似root["bg"] = "red"的事情吗?
    • 不,根目录包含Tk() 类,它无法处理后台选项。
    猜你喜欢
    • 2017-10-14
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 2022-07-04
    • 1970-01-01
    • 2013-10-13
    • 2011-01-16
    • 1970-01-01
    相关资源
    最近更新 更多