与小卡特一起学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))


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

转载于:http://blog.itpub.net/220205/viewspace-2072716/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值