猜数字草稿

import tkinter
import random
tk = tkinter.Tk()
tk.title('猜数字')

label_num = tkinter.Label(tk,text = '请输入您的数字:')
label_num.place(x = 10,y = 10,width = 100,height = 40)

entry_num = tkinter.Entry(tk,textvariable = tkinter.StringVar())
entry_num.place(x = 130,y = 10,width = 80,height = 40)

out1 = tkinter.StringVar()
n=int(random.random()*50+1)

def guess():
    i=1
    t = float(entry_num.get())
    if (i <= 5) and (t < n):
        out1.set('你猜的数字小了')
        i = i + 1
    elif (i <= 5) and (t > n):
        out1.set('你猜的数字大了')
        i = i + 1
    elif (i <= 5) and (t == n):
        out1.set('恭喜你猜对了')
        i = i + 1
    elif (i > 5) or (t == n):
        out1.set('你已经猜过五次,输了')


button_out = tkinter.Button(tk,text = '猜测',command = guess)
button_out.place(x = 130,y = 60,width = 80,height = 40)

entry_out1=tkinter.Entry(tk,textvariable = out1)
entry_out1.place(x = 130,y = 110,width = 340,height = 50)


tk.mainloop()


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值