我已经创建了一个名为“ lab”的全局标签。我试图首先将图像分配给标签,但是我想在用户从“添加图片”按钮添加新图像后进行更新。由于某种原因,我的标签未更新。
from tkinter import *
from PIL import Image, ImageTk
from tkinter.filedialog import askopenfilename
def putimage(pat):
image = Image.open(pat)
im = Image.open(pat).resize((100, 100), Image.ANTIALIAS)
photo = ImageTk.PhotoImage(im)
return photo
def makeregform():
window = Tk()
window.geometry("500x600")
p = putimage("sample.jpg")
global lab
lab = Label(image=p)
lab.pack()
window.title("Register User")
lablemain = Label(window, text="Registration Form", relief="solid", width=20, font=("arial", 19, "bold"))
lablemain.place(x=90, y=53 + 60)
login = Button(window, text="login", width=12, bg="brown", fg="white", command=putinfirebase)
login.place(x=80, y=450 + 60)
addpic = Button(window, text="Add Picture", width=12, bg="brown", fg="white", command=addphoto)
addpic.place(x=190, y=450 + 60)
def addphoto():
file = askopenfilename(title="Open File")
print(file)
n = putimage(file)
lab.configure(image = n)
if __name__ == '__main__':
makeregform()