1. 程式人生 > 其它 >gui關閉介面返回上一個介面_Python第五課 認識GUI

gui關閉介面返回上一個介面_Python第五課 認識GUI

技術標籤:gui關閉介面返回上一個介面

fbcdbeb1-1330-eb11-8da9-e4434bdf6706.png

GUI是Graphical User Interface(圖形使用者介面)的縮寫。就是程式與使用者互動的介面,手機上的叫UI。

我們之前寫的都是命令列和文字格式的程式,GUI是與程式互動的更有趣的方式,可以包含文字,影象,聲音,按鈕等等。

首先我們安裝Easygui這個模組。

然後在shell中寫下:

Import easygui
easygui.msgbox(‘hello world’)

執行如下出現了一個訊息框:

fccdbeb1-1330-eb11-8da9-e4434bdf6706.png

並且我們可以通過如下的程式碼收集使用者的操作資訊,是點選了右上角的關閉還是ok?

user_response=easygui.msgbox('hello world')
print(user_response)

可以執行一下看一下結果。

接下來介紹Buttonbox,輸入如下程式碼

import easygui
Color=easygui.buttonbox(‘what is your favorite color?’,
choices=[‘white’,’red’,’green’])
easygui.msgbox(‘you picked’+color)

執行如下

ffcdbeb1-1330-eb11-8da9-e4434bdf6706.png

02cebeb1-1330-eb11-8da9-e4434bdf6706.png

Easygui常用的其他元件還有choicebox和enterbox,更多的瞭解easygui可以訪問

http://easygui.sourceforge.net

公眾號:宜乎眾科技