关于python的easygui使用体验
# @Author : Miotsuki
# @Date : 2021/10/5
import random
import easygui as box
# 主界面
def home_page():
choices = ("剪刀", "石头", " 布 ")
return box.buttonbox(title = "石头剪刀布", choices=choices, msg=None,image='home_page.jpg')
# 判断用户和电脑的输赢情况
def judge(player,computer):
# 最简单的解决方式往往能处理最复杂的问题
if player == "石头":
if computer == "布":
return '你输了'
else:
return '你赢了'
elif player == "布":
if computer == "剪刀":
return '你输了'
else:
return '你赢了'
elif player == "剪刀":
if computer == "石头":
return '你输了'
else:
return '你赢了'
# 结果界面
def the_results(choice):
# 电脑随机一个选项(公平,公正,公开)
computer_choice = random.choice(("剪刀", "石头", "布"))
# 如果用户选择和电脑随机出来结果相同,则判断为平局
if choice == computer_choice:
msg = "平局"
# 不相同就去判断谁赢了
else:
msg = judge(choice,computer_choice)
# 编辑贴图
images = (f'{computer_choice}.png',f'{choice}.png')
# 修改提示信息
if msg == '你赢了':
ch = '太棒了!!!'
else:
ch = '好吧!'
# 这里出了bug,如果用户直接点机关闭的话会继续进行,所以判断用户是否点击了三个选项其中之一
if msg == None :
exit()
# 显示界面
box.buttonbox(title = "石头剪刀布",msg= msg,images=images,choices=(f"{ch}", ))
# 是否继续界面
def go_on():
if not box.ccbox(title = "石头剪刀布",msg="你还要继续吗?",choices = ("继续", "算了")):
return False
else:
return True
if __name__ == '__main__':
# 设置一个flag来判断是否还继续
flag = True
while flag:
choice = str(home_page()).strip()
the_results(choice)
flag = go_on()
下面是运行截图
总结:
easygui有显著的问题,太简单了,以至于很多东西都不够完善,无论是buttonbox还是msgbox都只有简单的流式布局,而且没有参数去设置,没法进行美观设计,不够实用,不能给用户好的人机交互体验。