python制作相册

python制作相册,第1张

包括四个按钮,上一页,下一页,首页,尾页

from tkinter import *
from PIL import Image, ImageTk

root = Tk()
root.title('相册')
path =path = './素材包/yuanshen/'

img=Image.open(path + '图片.jpg')
img = ImageTk.PhotoImage(img)

label = Label(root, width=980, height=500, image=img)
label.grid(row=0, column=0, columnspan=4)
current = 0


def callback_pre():
    global current
    current -= 1
    if current <= 0:
        current = 6
    img = Image.open(f'{path}{current}.jpg')
    img = ImageTk.PhotoImage(img)
    label.configure(image=img)
    label.Image = img
def nextback():
    global current
    current += 1
    if current >= 7:
        current = 1
    img = Image.open(f'{path}{current}.jpg')
    img = ImageTk.PhotoImage(img)
    label.configure(image=img)
    label.Image = img
def head():
    img = Image.open(f'{path}{1}.jpg')
    img = ImageTk.PhotoImage(img)
    label.configure(image=img)
    label.Image = img
def tail():
    img = Image.open(f'{path}{6}.jpg')
    img = ImageTk.PhotoImage(img)
    label.configure(image=img)
    label.Image = img

button_pre = Button(root, font=('黑体', 18), text='上一页', command=callback_pre)
button_pre.grid(row=1, column=0)
button_next = Button(root, font=('黑体', 18), text='下一页',command=nextback)
button_next.grid(row=1, column=1)
button_next = Button(root, font=('黑体', 18), text='首页',command=head)
button_next.grid(row=1, column=2)
button_next = Button(root, font=('黑体', 18), text='尾页',command=tail)
button_next.grid(row=1, column=3)
root.mainloop()

运行结果

photo

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/715010.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-25
下一篇 2022-04-25

发表评论

登录后才能评论

评论列表(0条)

保存