【问题标题】:How to change image and fit inside label?如何更改图像并适合标签内?
【发布时间】:2020-02-04 02:00:31
【问题描述】:
view = Tk()
view.title("Title")
view.geometry('600x600')
view.attributes("-fullscreen",True)

def resize_image(event):
    new_width = event.width
    new_height = event.height
    image = copy_of_image.resize((new_width, new_height))
    photo = ImageTk.PhotoImage(image)
    label.config(image = photo)
    label.image = photo 
image = Image.open('add.png')
copy_of_image = image.copy()
photo = ImageTk.PhotoImage(image)
label = ttk.Label(view, image = photo)
label.bind('<Configure>', resize_image)
label.pack(fill=BOTH, expand = YES)
command="pwd"

def changePicture():
    print("I change picture")
    image2 = Image.open('add.png')
    copy_of_image = image2.copy()
    photo = ImageTk.PhotoImage(image2)
    label = ttk.Label(view, image = photo)
    label.image=image2
    label.pack()

它只是站立,不能改变图片。我得到了“add.png”图像的其他代码。只是窗口保持静止,没有变化。提前感谢您的帮助。

【问题讨论】:

标签: python tkinter


【解决方案1】:

换行:

label.pack(fill=BOTH, expand = YES)

label.pack()

【讨论】:

  • 没有效果兄弟。我稍后用计时器调用 changePicture 函数。会不会造成这种情况?但是看到这个在改变时有效,但是我不能让它适合窗户。图像与其原始尺寸一样小。 ImageChange however it can't fit
猜你喜欢
  • 2022-01-14
  • 2013-02-10
  • 2015-01-15
  • 2011-05-04
  • 1970-01-01
  • 1970-01-01
  • 2021-12-18
  • 1970-01-01
相关资源
最近更新 更多