一、复习 1、easygui 信息提示对话框 2、easygui 是否对话框 二、easygui其它组件 1、选择对话框:choicebox(msg, title, choices) import easygui as gmsg = " 输入你喜欢的颜色 " title = " 游戏互动 " choices
一、复习
1、easygui 信息提示对话框
2、easygui 是否对话框
二、easygui其它组件
1、选择对话框:choicebox(msg, title, choices)
import easygui as g msg = "输入你喜欢的颜色" title = "游戏互动" choices = ["红色", "绿色", "蓝色", "青色"] choice = g.choicebox(msg, title, choices) g.msgbox("你喜欢的颜色是: " + choice)
2、按钮对话框:buttonbox(msg, title, choices)
import easygui as g msg = "输入你喜欢的颜色" title = "游戏互动" choices = ["红色", "绿色", "蓝色", "青色"] choice = g.buttonbox(msg, title, choices) g.msgbox("你喜欢的颜色是: " + choice)
3、输入对话框:enterbox(msg, title)
import easygui as g text = g.enterbox("请输入一句话", "title") g.msgbox(text)
4、多项输入对话框:multenterobx(msg, title, fields=[])
import easygui as g name, pass_ward = g.multenterbox("登录", "title", ["账号:", "密码:"]) print(name) print(pass_ward)
三、作业
1、将课堂练习照着在计算机上运行一遍
2、以下为猜数游戏的源代码,请将输入用输入对话框,print函数用信息提示对话框改写成一个gui的程序
import random secret = random.randint(1, 100) print("请猜一个1到100的数,你有6次机会") success = 0 for i in range(6): guess = int(input("请猜数:")) if guess < secret: print("你猜的数太小了") elif guess > secret: print("你猜的数太大了") else: success = 1 break if success == 1: print("恭喜你,你猜对了") else: print("对不起,你猜错了,秘密数为:", secret)
四、参考答案:
import random import easygui as g secret = random.randint(1, 100) g.msgbox("请猜一个1到100的数,你有6次机会") success = 0 for i in range(6): guess = int(g.enterbox("请输入你要猜的数")) if guess < secret: g.msgbox("你猜的数太小了") elif guess > secret: g.msgbox("你猜的数太大了") else: success = 1 break if success == 1: g.msgbox("恭喜你,你猜对了") else: g.msgbox("对不起,你猜错了,秘密数为:" + str(secret))