[英]How to display an image in a specific tkinter window using PhotoImage?
我有兩個運行 tkinter windows 但我只想要一個特定的 window 來顯示圖像,但我無法實現這一點。 我試圖在 Label 語句中指定 master,但 python 顯示錯誤“image pyimage1 doesn't exist” 請幫忙
import tkinter as tk
from PIL import Image, ImageTk
a=tk.Tk()
a.geometry('800x500+275+100')
a.title('HOME PAGE')
c=tk.Tk()
c.geometry('800x500+275+100')
c.title('PROFILE')
load=Image.open('untitled.png')
render=ImageTk.PhotoImage(load)
img=tk.Label(c,image=render)
img.pack()
a.mainloop()
c.mainloop()
如果你想要第二個屏幕使用tk.Toplevel
並刪除c.mainloop
a=tk.Tk()
a.geometry('800x500+275+100')
a.title('HOME PAGE')
c=tk.Toplevel()
c.geometry('800x500+275+100')
c.title('PROFILE')
load=Image.open('untitled.png')
render=ImageTk.PhotoImage(load)
img=tk.Label(c,image=render)
img.pack()
a.mainloop()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.