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()
11-11
2265