簡體   English   中英

調整圖片大小后,為什么我的圖像在Tkinter Python中消失了?

[英]Why does my image disappear in Tkinter Python After I Resize The Picture?

我確實有一些簡單的代碼。 我正在嘗試在Tkinter中調整大小並顯示圖像,但是由於某些原因,只有在調整了圖片的大小之后,它才會消失。 我正在使用Python 3.6和Tkinter,我確實是一個初學者。 這是代碼。 文件名為“ Icon For To-Do List.png”。

from tkinter import *
import datetime

root = Tk()
root.title("To - Do List")
root.geometry("1200x600")
root.configure(background = "white")
# Variable list:


Photo1= PhotoImage(file="Icon For To - Do List Yay.png", width=50, height=50)

Label(root, image=Photo1, bg="black").grid(row=0, column=0, sticky=W)
root.mainloop()

這是圖片。 它的尺寸為1000 x994。任何幫助將不勝感激。 非常感謝你!

您可以使用子樣本來調整圖像大小,而無需使用其他模塊

 BR = photo1.subsample(1, 2)

然后,您將其解析為標簽中的圖像。 您可以將整數增加或減少到您喜歡的大小

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM