簡體   English   中英

使用Tkinter GUI加載背景圖像

[英]Load background image with Tkinter GUI

我嘗試了所有與我的問題相關的Google帖子,但仍然無法解決。 我正在嘗試加載1張圖像作為tkinter生成表單的背景。 使用下面的代碼,我得到以下錯誤:追溯(最近一次調用):AttributeError:“ Label”對象中沒有屬性“ image1”的文件“”,第89行

下面是代碼:

   from tkinter import *
    import tkinter as tk
    from PIL import ImageTk, Image


    master = Tk()
    master1= Toplevel()
    master.title("Crop Yield Prediction")
    master.geometry('600x600')
   image2 = Image.open('D:\\Pictures\\god0a.jpg')
   image1 = ImageTk.PhotoImage(image2)
   background_label = tk.Label(master1, image=image1)
   background_label.image1
   background_label.photo=background
   background_label.place(x=0, y=0, relwidth=1, relheight=1)

很少修改代碼就可以了!!

image2 = Image.open('D:\\Pictures\\god0a.jpg')
#image2.show()
image1 = ImageTk.PhotoImage(image2)
background_label = tk.Label(master, image=image1)
background_label.image1=image1
background_label.place(x=0, y=0, height=250, width=350)

暫無
暫無

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

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