猫史档案馆


【Python作品分享】猜数字小游戏GUI版【作品秀】

用户:zichengjunzichengjun查看:0 回复:2 评论:0 创建时间:2020-03-04T20:09:28


【作品展示】

center_image

 

【作品介绍】

这个和别的命令提示符版猜数字小游戏不一样,是GUI版的。

注意:

这是我第一个作品,望大家能采纳

 

【作品源代码】

import random
from tkinter import *
cishu,numy=6,0
import time
numy=random.randint(1,20)
print('欢迎来到猜数字小游戏')
print('作者:丁子城')
print('QQ:1839067866')
def cais():
    global cishu,numy
    if cishu>0:
        if int(ent.get()) in range(1,21) and not ent.get()==None:
            if numy==int(ent.get()):
                tishi.config(text='恭喜你,猜对了! 开始新一轮')
                ok.config(state='disabled')
                time.sleep(2)
                ok.config(state='active')
                numy=random.randint(1,20)
                cishu=6
                ent.delete(0, END)
            else:
                if numyint(ent.get()):
                    tishi.config(text='猜小了!')
                    cishu=cishu-1
                    ent.delete(0, END)
                    fenshu.config(text='剩余次数:'+str(cishu))
        else:
            tishi.config(text='请输入正确的数!')
    else:
        tishi.config(text='次数用完!')
        time.sleep(1)
        tishi.config(text='正确的数是:'+str(numy)+'  开始新一轮')
        cishu=6


root=Tk(className='猜数字小游戏')
root.geometry('200x200')
lab1=Label(root,text='''请输入1到20之间的数
你有6次机会''')
lab1.pack()
fenshu=Label(root,text='剩余次数:6')
fenshu.pack()
ent=Entry()
ent.pack()
tishi=Label(root,text='   ',fg='red')
tishi.pack()
ok=Button(root,text='确定',command=cais)
ok.pack()
root.mainloop()

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
zichengjunzichengjun

放心,这个没有用第三方模块

点赞0


评论


cool-creepercool-creeper

额   .

点赞0


评论