英文:
Set image as window background Tkinter?
问题
I understand how to get an image into tkinter with ImageTk.PhotoImage(Image.open("Image"))
, but is it possible to set that image as the background of a window? I know that you can set it as a label then pack it into the window, but can you actually just set it as the background for the window?
我明白如何使用 ImageTk.PhotoImage(Image.open("Image"))
将图像加载到 tkinter 中,但是否可能将该图像设置为窗口的背景?我知道你可以将它设置为标签然后将其打包到窗口中,但是否可以直接将其设置为窗口的背景?
I tried to use the bg
argument of root.config()
, but it just came up with the error _tkinter.TclError: unknown color name "pyimage1"
, from which I deduced that that was not the way to go about it.
我尝试使用 root.config()
的 bg
参数,但它出现了错误 _tkinter.TclError: unknown color name "pyimage1"
,因此我推断这不是解决方法。
英文:
I understand how to get an image into tkinter with ImageTk.PhotoImage(Image.open("Image"))
, but is it possible to set that image as the background of a window? I know that you can set it as a label then pack it into the window, but can you actually just set it as the background for the window?
I tried to use the bg
argument of root.config()
, but it just came up with the error _tkinter.TclError: unknown color name "pyimage1"
, from which I deduced that that was not the way to go about it.
答案1
得分: 0
抱歉,我只会回应您要求的部分翻译,这是原文的翻译:
"不,根窗口和Toplevel
的实例不支持背景图像。创建一个带有图像的标签,并配置它以覆盖整个窗口是很简单的。然后,您可以将所有其他小部件放在该标签内。"
英文:
No, the root window and instances of Toplevel
do not support a background image. It’s trivial to create a label with an image, and configure it to cover the entire window. You can then put all other widgets inside the label.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论