①这里介绍EasyGui的几个常用函数的用法(后面会继续补充)
a.2018/1/25
②几道小题来练练手
msgbox()
msgbox(msg=’(Your message goes here)’, title=’ ‘, ok_button=’OK’, image=None, root=None)
msgbox() 显示一个消息和提供一个”OK”按钮,你可以指定任意的消息和标题,你甚至可以重写”OK”按钮的内容。(重写OK按钮只需要将ok_button改了即可
integerbox()
integerbox(msg=”, title=’ ‘, default=”, lowerbound=0, upperbound=99, image=None, root=None, **invalidKeywordArguments)
integerbox() 为用户提供一个简单的输入框,用户只能输入范围内(lowerbound参数设置最小值,upperbound参数设置最大值)的整型数值,否则会要求用户重新输入。
例1 数字游戏
import easygui as g
import random
g.msgbox('嗨,欢迎进入第一个小游戏')
secret = random.randint(1,10)
msg = '不防猜一下现在是哪个数字(1~10)'
title = '数字小游戏'
guess = g.integerbox(msg, title, lowerbound = 1,upperbound = 10)
while True:
if guess == secret:
g.msgbox('回答正确')
break
else:
if guess > secret:
g.msgbox('数字大了')