python 用 GUI 的 tkinter 写一个 猜数字游戏
from tkinter import *
import tkinter.simpledialog as dl
import tkinter.messagebox as mb
#设置GUI
root = Tk()
w = Label(root,text="猜数字游戏")
w.pack()
mb.showinfo("欢迎", "欢迎参加猜数字游戏")
number = 38#游戏的答案是38
while True:
guess = dl.askinteger("Number","请输入你猜的数字!")
if guess == number:
output = "恭喜你,猜对啦!但是没有见奖品哦!"
mb.showinfo("Hint: ",output)
break
elif guess < number:
output = "猜错了,答案应该更大一些!"
mb.showinfo("Hint: ",output)
else:
output = "猜错了,答案应该更小一些!"
mb.showinfo("Hint: ", output)
print("Done")