- 论坛徽章:
- 0
|
代码如下
- import os,sys,math,random,time
- from glob import glob
- #from time import sleep
- from Tkinter import *
- import Image
- from ImageTk import PhotoImage
- def ran():
- num = random.randint(1,44)
- print num
- try:
- imgpath = "pic/" + str(num) + ".JPG"
- print imgpath
- img = PhotoImage(file=imgpath)
- canvas.create_image(0,0,image=img,anchor="nw")
- except IOError:
- showerror('Photos',"This file isn't image.")
- pass
- #=======init======#
- top = Tk()
- b1 = Button(top,text='start',command=ran)
- b1.pack(side='left')
- canvas = Canvas(top)
- canvas.config(width=1024,height=768)
- #img = PhotoImage(file="pic/12.jpg")
- canvas.pack(side='top',expand='YES',fill='both')
- #canvas.create_image(0,0,image=img,anchor="nw")
- #imglist = [img for img in os.listdir('./pic')]
- #==================#
- top.mainloop()
复制代码 |
|