# 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))
#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))
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/220205/viewspace-2072716/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/220205/viewspace-2072716/