python -猜字小游戏
2018-08-05 07:51:06来源:博客园 阅读 ()
代码运行效果如下:
注意:
1.必须要在python3环境想使用
2.QQ:3084276329(一起交流学习)
3.还请大家评论
Guess the word game代码如下:
1 #! /usr/bin/env python 2 # -*- coding: utf-8 -*- 3 # Guess the word game 4 # 博客:https://www.cnblogs.com/muxii 5 # 那个木兮啊 6 import tkinter 7 import threading 8 import time 9 from tkinter import * 10 from tkinter import messagebox 11 from tkinter import messagebox 12 13 root = tkinter.Tk() 14 root.title('那个木兮啊-Guess the word') 15 root.minsize(300,330) 16 17 label =(root) 18 label = Label(root,text = '博客:https://www.cnblogs.com/muxii/\nQQ:3084276329\n—-————那个木兮啊——-———',font = ('微软雅黑',11),fg = 'red') 19 label.grid(row =0 ,column =0) 20 btn1 = tkinter.Button(root,text ='1',width = 5,height =2,bg='blue') 21 btn1.place(x=20,y=70) 22 btn2 = tkinter.Button(root,text = '2',width = 5,height =2,bg ='white') 23 btn2.place(x=90,y=70) 24 btn3 = tkinter.Button(root,text = '3',width = 5,height =2,bg ='white') 25 btn3.place(x=160,y=70) 26 btn4 = tkinter.Button(root,text = '3',width = 5,height =2,bg ='white') 27 btn4.place(x=230,y=140) 28 btn5 = tkinter.Button(root,text = '5',width = 5,height =2,bg ='white') 29 btn5.place(x=230,y=70) 30 btn6 = tkinter.Button(root,text = '6',width = 5,height =2,bg ='white') 31 btn6.place(x=230,y=210) 32 btn7 = tkinter.Button(root,text = '7',width = 5,height =2,bg ='white') 33 btn7.place(x=230,y=280 ) 34 btn8 = tkinter.Button(root,text = '8',width = 5,height =2,bg ='white') 35 btn8.place(x=160,y=280) 36 btn9 = tkinter.Button(root,text = '9',width = 5,height =2,bg ='white') 37 btn9.place(x=90,y=280 ) 38 btn10 = tkinter.Button(root,text = '10',width = 5,height =2,bg ='white') 39 btn10.place(x=20,y=280) 40 btn11 = tkinter.Button(root,text = '11',width = 5,height =2,bg ='white') 41 btn11.place(x=20,y=210) 42 btn12 = tkinter.Button(root,text = '12',width = 5,height =2,bg ='white') 43 btn12.place(x=20,y=140) 44 herolists = [btn1,btn2,btn3,btn4,btn5,btn6,btn7,btn8,btn9,btn11] 45 46 isloop = False 47 48 stopsing = False 49 #定义停止id 50 stopid = None 51 52 #定义函数,循环选项 设置背景颜色,选中的为红色, 53 def round(): 54 global isloop 55 global stopid 56 if isloop ==True: 57 return 58 i = 1 59 #判断一个对象是否已经类型 type 60 #考虑继承关系 61 if isinstance(stopid,int): 62 i = stopid 63 64 while True: 65 # 66 time.sleep(0.05)#延时 67 for x in herolists: 68 x['bg'] = 'white' 69 70 herolists[i]['bg'] ='blue' 71 72 i += 1 73 74 75 if i >= len(herolists): 76 i = 0 77 78 if stopsing == True: 79 isloop =False 80 stopid = i 81 break 82 83 #停止 84 def stop1(): 85 86 global stopsing 87 88 if stopsing == True: 89 return 90 stopsing = True 91 92 #开始 93 def newtask(): 94 global isloop 95 global stopsing 96 stopsing = False 97 #建立线程 98 t = threading.Thread(target = round ) 99 t.start() 100 isloop = True 101 102 btn_start = tkinter.Button(root,text = '开始',bg = 'red',command = newtask) 103 btn_start.place(x=90,y=175) 104 # 105 btn_stop = tkinter.Button(root,text = '结束',bg = 'yellow',command = stop1) 106 btn_stop.place(x=160,y=175 ) 107 108 root.mainloop()
2018.8.3
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- python3基础之“术语表(2)” 2019-08-13
- python3 之 字符串编码小结(Unicode、utf-8、gbk、gb2312等 2019-08-13
- Python3安装impala 2019-08-13
- 小白如何入门 Python 爬虫? 2019-08-13
- python_字符串方法 2019-08-13
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash