與小卡特一起學python 第6章 gui-圖形使用者介面 6-1-2-3-4-5 gui使用

yarking207發表於2016-03-30
# 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/,如需轉載,請註明出處,否則將追究法律責任。

相關文章