2. 逻辑层
例:
from tkinter import * #tkinter是Python中一个GUI的库,提供一些现成的可以直接用来快速开发图形界面的相关应用,使用时需要先导入tkinter库
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')