python图片播放器

python图片播放器能够定时播放图片,现在功能比较简单,如果阅读后感兴趣,请留言,我能根据需要增加功能.
建立图片文件夹"pic"放入停止,播放按钮
在这里插入图片描述
在这里插入图片描述
建立图片文件夹"demo"放入png图片
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

# -*- coding: utf-8 -*-
import os
from tkinter import *
import datetime
import time
from  random import randint
k=0

class baseFrame:         #模板类
    
         def __init__(self, master,user,framename):
              self.root = master
              self.user=user
              self.framename=framename
              #self.root.resizable(0,0)
              self.root.title(self.framename+self.user)
              width =800
              height = 600
              screenwidth = self.root.winfo_screenwidth()
              screenheight = self.root.winfo_screenheight()
              alignstr = '%dx%d+%d+%d' % (width, height, (screenwidth-width)/2, (screenheight-height)/2)
              self.root.geometry(alignstr)
              #self.root.iconbitmap(".\\pic\\smart.ico")
              self.root.wm_attributes("-topmost", 1)
              self.baseframe_ui()
              
         def baseframe_ui(self):
              self.one = Label(self.root, text="© Powered by Will Wu "+"2020-"+str(datetime.datetime.now().year), width=30, height=2, font=("Arial", 10))
              self.one.pack(side=BOTTOM)
                    
              
class  show_wi(baseFrame):  #显示类
    
         def __init__(self,master,user,framename):   
               super( ).__init__(master,user,framename)
               self.photo_play=PhotoImage(file=os.getcwd()+".\\pic\\play.png")
               self.photo_stop=PhotoImage(file=os.getcwd()+".\\pic\\stop.png")    
               self.add_ui()
               self.files=self.file_list()
               
         def add_ui(self):
               self.button_back=Button(self.root,image=self.photo_play,command=self.auto_update)
               self.button_back.place(relx=0.8,rely=0.91)               
               self.button_back=Button(self.root,image=self.photo_stop,command=self.cancel_auto)
               self.button_back.place(relx=0.9,rely=0.91)

         def file_list(self):
                filelist=[]
                path=os.getcwd()+"\\demo\\"
                for i in os.listdir(path):
                         f=os.path.join(path,i)
                         if f.endswith("PNG"):
                             filelist.append(i)
                return filelist
                                       
         def play(self,filename):              
                self.demo=PhotoImage(file=os.getcwd()+"\\demo\\"+filename)
                self.Label = Label(self.root,image=self.demo,fg="white")
                self.Label.place(relx=0.2,rely=0.2)
                                   
         def auto_update(self):
               global k
               global up
               if  k<len(self.files):
                       self.play(self.files[k])
                       k=k+1
                       up=self.root.after(500,self.auto_update)
               else:
                     k=0
                     up=self.root.after(500,self.auto_update)
  
         def cancel_auto(self):
                root.after_cancel(up)

                
               
if __name__ == '__main__':
    root = Tk()
    show_wi(root,"usertest","图片播放")
    root.mainloop()



`

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值