gpt4 book ai didi

Python button选取本地图片并显示的实例

转载 作者:qq735679552 更新时间:2022-09-28 22:32:09 30 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章Python button选取本地图片并显示的实例由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

从本地文件夹中选取一张图片并在canvas上显示 。

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from tkinter import *
from tkinter import filedialog
from pil import image, imagetk
 
if __name__ = = "__main__" :
   root = tk()
 
   #setting up a tkinter canvas with scrollbars
   frame = frame(root, bd = 2 , relief = sunken)
   frame.grid_rowconfigure( 0 , weight = 1 )
   frame.grid_columnconfigure( 0 , weight = 1 )
   xscroll = scrollbar(frame, orient = horizontal)
   xscroll.grid(row = 1 , column = 0 , sticky = e + w)
   yscroll = scrollbar(frame)
   yscroll.grid(row = 0 , column = 1 , sticky = n + s)
   canvas = canvas(frame, bd = 0 , xscrollcommand = xscroll. set , yscrollcommand = yscroll. set )
   canvas.grid(row = 0 , column = 0 , sticky = n + s + e + w)
   xscroll.config(command = canvas.xview)
   yscroll.config(command = canvas.yview)
   frame.pack(fill = both,expand = 1 )
 
 
   #function to be called when mouse is clicked
   def printcoords():
     file = filedialog.askopenfilename(parent = root, initialdir = "c:/" ,title = 'choose an image.' )
     filename = imagetk.photoimage(image. open ( file ))
     canvas.image = filename # <--- keep reference of your image
     canvas.create_image( 0 , 0 ,anchor = 'nw' ,image = filename)
 
   button(root,text = 'choose' ,command = printcoords).pack()
   root.mainloop()

以上这篇python button选取本地图片并显示的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我.

原文链接:https://blog.csdn.net/YuMingJing_/article/details/79603579 。

最后此篇关于Python button选取本地图片并显示的实例的文章就讲到这里了,如果你想了解更多关于Python button选取本地图片并显示的实例的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com