# 与小卡特一起学python 第6章 gui-图形用户界面 6-1-2-3-4-5 gui使用

# Easygui 安装  python.exe setup.py install
#6-1使用按钮得到输入
import easygui
flavor = easygui.buttonbox("What is your favorite ice cream flavor?",
choices = ['Vanilla','Chocolate','Strawberry'])
easygui.msgbox("You picked"+ flavor)
#6-2使用选择框得到输入
import easygui
flavor = easygui.choicebox("What is your favorite ice cream flavor?",
choices = ['Vanilla','Chocolate','Strawberry'])
easygui.msgbox("You picked"+ flavor)
#6-3使用输入框得到输入
import easygui
flavor = easygui.enterbox("What's your favorite ice cream flavor?")
easygui.msgbox("You entered" + flavor)
#6-4如何建立一个默认参数
import easygui
flavor = easygui.enterbox("What's your favorite ice cream flavor?",
default = 'Vanilla')
easygui.msgbox("You entered" + flavor)
#6-5 使用easygui的猜数游戏
import random,easygui
secret = random.randint(1,99)
guess = 0
tries = 0
easygui.msgbox("""AHOY! I'm the Dread Pirate Roberts,and I have a secret~
It's a number from 1 to 99. I'll give you 6 tries.""")
while guess != secret and tries < 6:
guess = easygui.integerbox("What's yer guess,matey?")
if not guess:break
if guess < secret:
easygui.msgbox(str(guess) + "is too low, ye scurvy dog!")
elif guess >secret:
easygui.msgbox(str(guess)+ " is too high, landlubber!")
tries = tries + 1
if guess == secret:
easygui.msgbox("Avast!Ye got it! Found my secret,ye did!secret is"+str(secret))
else:
easygui.msgbox("No more guesses! The number was" + str(secret))

• 博文量
65
• 访问量
78605