【Python作品分享】王者相册【作品秀】

【作品展示】
【作品介绍】

王者相册
【作品源代码】

# 王者相册
from tkinter import *
from PIL import Image
from PIL import ImageTk
import os

root = Tk()
root.title('王者相册')

current_img_name = 1
# 本地图片的路径
img_path = "./"
# 打开图片
img_list = os.listdir(img_path)
img = Image.open(img_path + "1.jpg")
img = ImageTk.PhotoImage(img)


# 定义标签
label = Label(root, width=1000, height=500, image = img)
label.grid(row=0, column=0, columnspan=2)

# 上一张按钮事件函数
def callback_pre():
    global current_img_name
    current_img_name -= 1
    if current_img_name == 0:
        current_img_name = 30
    img_new = Image.open(img_path + str(current_img_name) + ".jpg")
    img_new = ImageTk.PhotoImage(img_new)
    # 更改指向
    label.configure(image = img_new)
    label.image = img_new

# 下一张按钮
全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务