8.2_猜数字游戏
#1. GUI from tkinter
#2. 逻辑层
Code:
from tkinter import *
import tkinter.simpledialog as dl
import tkinter.messagebox as mb
#设置GUI
root = Tk()
w = Label(root, text = "Guess Number Game")
w.pack()
#欢迎消息
mb.showinfo("Welcome", "Welcome to Guess Number Game")
#处理信息
number = 59
while True:
#让用户输入信息
guess = dl.askinteger("Number", "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)
print('Done')
|
🐳 作者:hiszm 📢 版权:本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,万分感谢。 💬 留言:同时 , 如果文中有什么错误,欢迎指出。以免更多的人被误导。 |
![]() |


浙公网安备 33010602011771号