Py之tkinter:python最简单的猜字小游戏带你进入python的GUI世界——daidingdaiding

Py之tkinter:python最简单的猜字小游戏带你进入python的GUI世界——daidingdaiding

 

 

 

目录

输出结果

设计思路


 

 

 

 

 

 

输出结果

 

设计思路

from tkinter import *  
import tkinter.simpledialog as dl  
import tkinter.messagebox as mb    

root = Tk()   
w = Label(root, text = "Guess Number Game") 
w.pack()      

mb.showinfo("yunyaniu", "Welcome to Guess Number Game")  

number = 2018
while True:
    guess = dl.askinteger("yunyaniu", "What's your guess?") 
    if guess == number:
        # New block starts here
        output = 'Bingo! you guessed it right, but you do not win any prizes!'
        mb.showinfo("Hint: ", output)
        break
        # New block ends here
    elif guess < number:
        output = 'No, the number is a  higer than that'
        mb.showinfo("Hint: ", output)
    else:
        output = 'No, the number is a  lower than that'
        mb.showinfo("Hint: ", output)
mb.showinfo("yunyaniu","Thank you for your participation!") 

print('Game over!')  

 

 

 

 

 

 

 

 

 

 

 

发布了1565 篇原创文章 · 获赞 6112 · 访问量 1186万+

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 代码科技 设计师: Amelia_0503

分享到微信朋友圈

×

扫一扫,手机浏览