我无法使用按钮单击在画布上显示图像
我无法将图像添加到画布中,我想要的是,当单击文件管理器打开的按钮时,我可以选择一个映像,然后单击“打开”以加载图像,
这是我的代码: -
canvas=Canvas(width=200, height=200)
browse=Button(text="Browse")
canvas.place(x=440, y=80)
browse.place(x=480, y=300)
global photos
def browseFiles():
filename = filedialog.askopenfilename(initialdir = "/",
title = "Select a File",
filetypes = (("Text files",
"*.jpg*"),
("all files",
"*.*")))
image = (Image.open(filename))
resize_image = image.resize((200, 200))
photos = ImageTk.PhotoImage(resize_image)
canvas.create_image(100, 100, image=photos)
browse.config(command=browseFiles)
I am not able to add an image to a canvas, what I want is when clicked on the button the file manager opens and then I can select an image and click open to load the image
this is my code:-
canvas=Canvas(width=200, height=200)
browse=Button(text="Browse")
canvas.place(x=440, y=80)
browse.place(x=480, y=300)
global photos
def browseFiles():
filename = filedialog.askopenfilename(initialdir = "/",
title = "Select a File",
filetypes = (("Text files",
"*.jpg*"),
("all files",
"*.*")))
image = (Image.open(filename))
resize_image = image.resize((200, 200))
photos = ImageTk.PhotoImage(resize_image)
canvas.create_image(100, 100, image=photos)
browse.config(command=browseFiles)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论