2008-10-01

Python -- EasyGUI

Python是個功能很多的語言,但是如果你並不需要太多複雜的功能,又想要有GUI介面,那EasyGUI是個很棒的選擇!

它的安裝跟下載簡單到只是一個檔案,放到讓Python可以找到的地方就好!在Windows下,建議放到\pythonxx\lib\site-packages裡面就好。不過你下載的檔案,並不會自行產生目錄,所以我個人建議是你把它解到site-packages下一個叫做easygui的目錄,然後單獨把easygui.py放在\pythonxx\lib\site-packages下就好.

下面就是一個easygui本身的範例,簡單吧?只要from...import...或直接import也行啦,看你高興!接下來,你就可以讓你寫好的程式擁有GUI介面,這對許多小工具或者自己寫的輔助程式將會非常有幫助!

from easygui import *
import sys

while 1:
msgbox("Hello, world!")

msg ="What is your favorite flavor?"
title = "Ice Cream Survey"
choices = ["Vanilla", "Chocolate", "Strawberry", "Rocky Road"]
choice = choicebox(msg, title, choices)

# note that we convert choice to string, in case
# the user cancelled the choice, and we got None.
msgbox("You chose: " + str(choice), "Survey Result")

msg = "Do you want to continue?"
title = "Please Confirm"
if ccbox(msg, title): # show a Continue/Cancel dialog
pass # user chose Continue
else:
sys.exit(0) # user chose Cancel

沒有留言: