0

我一直在尝试将图像作为我的项目的背景。我发现了一些将它放在标签中的代码,这工作正常,除了它的大小似乎不起作用并且两侧出现空白空间(见图)在此处输入图像描述

我的代码是:

from tkinter import *
from PIL import ImageTk, Image


#make a window
ws = Tk()
ws.title("window")

#get wigth & height of screen
width= ws.winfo_screenwidth()
height= ws.winfo_screenheight()

#set screensize as fullscreen and not resizable
ws.geometry("%dx%d" % (width, height))
ws.resizable(False, False)

# put image in a label and place label as background
imgTemp = Image.open("images/wallpaper.png")
img2 = imgTemp.resize((height,1800))
img = ImageTk.PhotoImage(img2)

label = Label(ws,image=img)
label.pack(side='top',fill=Y,expand=True)

#text = Text(ws,height=10,width=53)
#text.place(x=30, y=50)

#button = Button(ws,text='SEND',relief=RAISED,font=('Arial Bold', 18))
#button.place(x=190, y=250)

ws.mainloop()
4

0 回答 0