稍微修改一下代碼:from tkinter import *
from tkinter import messagebox as m
import random
root = Tk()
root.title("猜数字")
root.geometry("250x150")
TIME = 0
answer = random.randint(1,100)
gepi = ('个屁,正确答案是',answer)
def check():
eg = int(en.get())
global TIME
TIME += 1
if TIME > 5:
m.showinfo('正确','恭喜你答对了')
m.showinfo('个屁',gepi)
root.destroy()
elif eg == answer:
m.showinfo('正确','恭喜你答对了')
root.destroy()
elif (eg > 100)or(eg < 1):
m.showinfo('输入错误','请输入1~100的整数')
elif eg > answer:
m.showinfo('错误','你猜大了')
elif eg < answer:
m.showinfo('错误','你猜小了')
Label(root, text = '1~100选一个数', bg = 'yellow', fg = 'blue',
font = ('华文行楷', 15)).place(x = 50, y = 0)
a = Entry(root, bg = 'yellow', fg = 'blue', font = ('华文行楷', 15))
a.place(x = 20, y = 50)
b = Button(root, text='提交', bg = 'yellow', fg = 'blue', font = ('华文行楷', 15), command = check)
b.place(x = 80, y = 90)
root.mainloop()
|