天天看點

Py之tkinter:python最簡單的猜字小遊戲帶你進入python的GUI世界

輸出結果

https://img-blog.csdn.net/20180306162419556?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvcXFfNDExODU4Njg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70

設計思路

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'

   else:

       output = 'No, the number is a  lower than that'

mb.showinfo("yunyaniu","Thank you for your participation!")

print('Game over!')