import random
num = random.randint(1,500)
running = True
times = 0 ##总的次数
from tkinter import* ##导入所有tkinter的函数
root = Tk() ##root表示主窗口
root.title("猜价钱游戏") ##标题
root.resizable(0,0) ##表示框体的X,Y方向可以自由拉升不,1为可以。0为不可以
root.geometry('300x150') ##框体大小设置
def onClick1():
global num ##全局变量
global times
times = times+1
if int(w.get())== num:
result = "你猜对了"
elif int(w.get())>num:
result = "偏高"
else:
result = "偏低"
dis2.config(text = result+" 第%d次"%times)
dis1 = Label(root,text = "请输入一个1-1000之间的数",height = 2, width =24, fg = "black")
##长宽,字体颜色,背景颜色
w = Entry(root) ##单行输入框
button1 = Button(root,text = "提交",fg = 'red',command = onClick1,height = 1, width =8,)
dis2= Label(root,height = 2, width =20,)
dis1.pack()
w.pack()
button1.pack()
dis2.pack()
root.mainloop() ##进入消息循环,必须要有这个函数