【问题标题】:Readjusting background image in Tkinter?在 Tkinter 中重新调整背景图像?
【发布时间】:2017-11-15 10:14:00
【问题描述】:

我尝试将图像放置在 tkinter 窗口的背景中,并添加了按钮,但图像会自动放置在两个按钮之间(左下角和右下角放置按钮)并且图像不会水平拉伸。

我们如何使图像在背景中拉伸?
(我在 python 3.6.1 中使用 tkinter)

【问题讨论】:

  • 您需要包含 minimalcompleteverifiable 示例,否则我们无法为您提供帮助。请参阅this guide 寻求帮助。

标签: python python-3.x tkinter


【解决方案1】:

猜测你的代码是什么样子的,将图像文件更改为你想要用作背景的文件。

from tkinter import *

root = Tk()
root.geometry("400x400")


lb = PhotoImage(file="Background image.png") # repalce with your file name
label = Label(root, image=lb)
label.place(x=0, y=0, relwidth=1, relheight=1)

Button1 = Button(root, text="my button one").pack(side="left")
Button = Button(root, text="my button two").pack(side="right")

root.mainloop()

如果您需要更多帮助,请在评论框中留言

【讨论】:

  • 这不会添加图像作为背景,它会添加相对于窗口大小为 0 的图像,这意味着它不可见。如果您尝试添加具有背景窗口大小的图像,则它应该是relwidth=1, relheight=1。这也不会考虑窗口大小或图像缩放的变化。
猜你喜欢
  • 2014-07-26
  • 1970-01-01
  • 1970-01-01
  • 2017-10-14
  • 2019-08-04
  • 1970-01-01
  • 1970-01-01
  • 2020-11-15
  • 1970-01-01
相关资源
最近更新 更多