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')
本文介绍了一个使用Python的tkinter库实现的简单图形界面猜数字游戏。玩家通过交互界面输入猜测的数字,程序会根据玩家的输入给出提示,直至猜中设定的数字。
7715

被折叠的 条评论
为什么被折叠?



