ITPub博客

首页 > 应用开发 > IT综合 > 与小卡特一起学python 第6章 gui-图形用户界面 6-1-2-3-4-5 gui使用

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

原创 IT综合 作者:yarking207 时间:2016-03-30 22:57:17 0 删除 编辑
# 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/,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2011-08-03

  • 博文量
    65
  • 访问量
    78605