日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

Python编程:制作电子相册

發布時間:2024/9/20 python 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python编程:制作电子相册 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

本文博客鏈接:http://blog.csdn.net/jdh99,作者:jdh,轉載請注明.

環境:

主機:WIN10

python版本:3.5

開發環境:pyCharm 5.0.2


說明:
家里有不用的windows平板me400c,用python編寫一個腳本,實現電子相冊功能。
功能:
1.每5s自動播放下一張
2.可以手動點擊,播放下一張

效果:


源代碼:


import os
import threading
import tkinter as tk
?
import time
from PIL import ImageTk, Image
?
#分辨率
resolution = (1366, 768)
# 路徑
Path = 'd:\photo'
# 播放間隔.單位:s
Interval = 5
# 當前照片計數
Index = 0
?
scaler = Image.ANTIALIAS
?
root = tk.Tk()
?
img_in = Image.open("load.jpg")
w, h = img_in.size
size_new = ((int)(w * resolution[1] / h), resolution[1])
img_out = img_in.resize(size_new, scaler)
img = ImageTk.PhotoImage(img_out)
# img = ImageTk.PhotoImage(Image.open("load.jpg"))
panel = tk.Label(root, image = img)
panel.pack(side = "bottom", fill = "both", expand = "yes")
?
?
def callback(e):
? ? global Index
?
? ? files = os.listdir(Path)
? ? i = 0
? ? for x in files:
? ? ? ? # 判斷文件是否存在
? ? ? ? if not os.path.isfile(Path + '\%s' % x):
? ? ? ? ? ? break
?
? ? ? ? if i < Index:
? ? ? ? ? ? i += 1
? ? ? ? ? ? continue
?
? ? ? ? print('手動處理圖片', x, Index)
? ? ? ? if not (x.endswith('.jpg') or x.endswith('.JPG')):
? ? ? ? ? ? i += 1
? ? ? ? ? ? Index += 1
? ? ? ? ? ? if Index >= len(files):
? ? ? ? ? ? ? ? Index = 0
? ? ? ? ? ? continue
?
? ? ? ? img_in = Image.open(Path + '\%s' % x)
? ? ? ? print(img_in)
? ? ? ? w, h = img_in.size
? ? ? ? size_new = ((int)(w * resolution[1] / h), resolution[1])
? ? ? ? img_out = img_in.resize(size_new, scaler)
? ? ? ? img2 = ImageTk.PhotoImage(img_out)
? ? ? ? # img2 = ImageTk.PhotoImage(Image.open(Path + '\%s' % x))
? ? ? ? panel.configure(image=img2)
? ? ? ? panel.image = img2
? ? ? ? Index += 1
? ? ? ? if Index >= len(files):
? ? ? ? ? ? Index = 0
? ? ? ? break
?
# root.bind("<Return>", callback)
root.bind("<Button-1>", callback)
?
?
def image_change():
? ? global Index
?
? ? time.sleep(3)
? ? while True:
? ? ? ? files = os.listdir(Path)
? ? ? ? i = 0
? ? ? ? for x in files:
? ? ? ? ? ? # 判斷文件是否存在
? ? ? ? ? ? if not os.path.isfile(Path + '\%s' % x):
? ? ? ? ? ? ? ? break
?
? ? ? ? ? ? if i < Index:
? ? ? ? ? ? ? ? i += 1
? ? ? ? ? ? ? ? continue
?
? ? ? ? ? ? print('自動處理圖片', x, Index)
? ? ? ? ? ? if not (x.endswith('.jpg') or x.endswith('.JPG')):
? ? ? ? ? ? ? ? i += 1
? ? ? ? ? ? ? ? Index += 1
? ? ? ? ? ? ? ? if Index >= len(files):
? ? ? ? ? ? ? ? ? ? Index = 0
? ? ? ? ? ? ? ? continue
?
? ? ? ? ? ? img_in = Image.open(Path + '\%s' % x)
? ? ? ? ? ? w, h = img_in.size
? ? ? ? ? ? size_new = ((int)(w * resolution[1] / h), resolution[1])
? ? ? ? ? ? img_out = img_in.resize(size_new, scaler)
? ? ? ? ? ? img2 = ImageTk.PhotoImage(img_out)
? ? ? ? ? ? # img2 = ImageTk.PhotoImage(Image.open(Path + '\%s' % x))
? ? ? ? ? ? panel.configure(image=img2)
? ? ? ? ? ? panel.image = img2
? ? ? ? ? ? Index += 1
? ? ? ? ? ? if Index >= len(files):
? ? ? ? ? ? ? ? Index = 0
? ? ? ? ? ? time.sleep(Interval)
?
# 圖片切換線程
t = threading.Thread(target=image_change)
t.start()
?
root.mainloop()
?

————————————————
版權聲明:本文為CSDN博主「jdh99」的原創文章,遵循CC 4.0 BY-SA版權協議,轉載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/jdh99/article/details/52080514

總結

以上是生活随笔為你收集整理的Python编程:制作电子相册的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。