python 用 GUI 的 tkinter 写一个 猜数字游戏

版权声明:欢迎转载,如果转载,请注明转载地址,谢谢你啦!觉得文章不错的话右上角点个赞再走呀! https://blog.csdn.net/qq_40763929/article/details/88671469
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")

猜你喜欢

转载自blog.csdn.net/qq_40763929/article/details/88671469