python制作相册

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

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

  • 4
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值