免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1902 | 回复: 0
打印 上一主题 下一主题

为什么我按下按键后没有不显示图片呢? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-01-16 12:23 |只看该作者 |倒序浏览
代码如下


  1. import os,sys,math,random,time  
  2. from glob import glob   

  3. #from time import sleep
  4. from Tkinter import *   
  5. import Image   
  6. from ImageTk import PhotoImage

  7. def ran():
  8.   num = random.randint(1,44)
  9.   print num
  10.   try:
  11.     imgpath = "pic/" + str(num) + ".JPG"
  12.     print imgpath
  13.     img = PhotoImage(file=imgpath)
  14.     canvas.create_image(0,0,image=img,anchor="nw")
  15.   except IOError:
  16.     showerror('Photos',"This file isn't image.")
  17.     pass

  18. #=======init======#
  19. top = Tk()
  20. b1 = Button(top,text='start',command=ran)
  21. b1.pack(side='left')
  22. canvas = Canvas(top)
  23. canvas.config(width=1024,height=768)
  24. #img = PhotoImage(file="pic/12.jpg")
  25. canvas.pack(side='top',expand='YES',fill='both')
  26. #canvas.create_image(0,0,image=img,anchor="nw")
  27. #imglist = [img for img in os.listdir('./pic')]
  28. #==================#


  29. top.mainloop()


复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP