撰寫日期:2020年2月1日
PySimpleGUI是一個Python的GUI框架,以Tkinter、Pyqt和wxPython為后端煮纵,簡化了Python GUI編程机错,可以說是目前創(chuàng)建python界面最方便快捷的框架。
PySimpleGUI的GitHub地址為:https://github.com/PySimpleGUI/PySimpleGUI
其中的readme即為文檔。
另外文檔也可以閱讀這里:https://pysimplegui.readthedocs.io/en/latest/#platforms
目前椅邓,PySimpleGUI已經(jīng)停止支持Python 2(截止至2020-1-1)柠逞,所以建議使用Python 3.
一、系統(tǒng)環(huán)境
- Windows 10 64bit 1909
二景馁、Python 3.7 安裝PySimpleGUI
Python 3最好使用Python 3.7.2(包含)及其之前的版本板壮。Python 3.7.3及其之后的版本使用table colors時有問題。
詳情參見官方文檔:
Warning - tkinter + Python 3.7.3 and later, including 3.8 has problems
The version of tkinter that is being supplied with the 3.7.3 and later versions of Python is known to have a problem with table colors. Basically, they don't work. As a result, if you want to use the plain PySimpleGUI running on tkinter, you should be using 3.7.2 or less. 3.6 is the version PySimpleGUI has chosen as the recommended version for most users.
Python 3.7 安裝PySimpleGUI極其簡單合住,直接輸入如下命令即可:
pip install PySimpleGUI
三绰精、Python 2.7 安裝PySimpleGUI27
下面主要說明Python 2下的安裝,我使用的版本是Python 2.7.5 32bit透葛。安裝之前先看這句話笨使,引用自官方文檔:
As of 9/25/2018 both Python 3 and Python 2.7 are supported when using tkinter version of PySimpleGUI! The Python 3 version is named
PySimpleGUI
. The Python 2.7 version isPySimpleGUI27
. They are installed separately and the imports are different. See instructions in Installation section for more info. None of the other ports can use Python 2.
也就是說,在Python 2.7下获洲,安裝包名稱是PySimpleGUI27阱表,而不是PySimpleGUI。
直接采用pypi上面的pip install PySimpleGUI27
并不能得到正確安裝該包贡珊,而且可能會報Could not find a version that satisfies....的錯誤最爬。
(1)安裝之前,最好更新pip
更新命令為:python -m pip install --upgrade pip
(2)采用豆瓣源安裝PySimpleGUI27及依賴包typing
pip install PySimpleGUI27 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
pip install typing -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
- PySimpleGUI27依賴future包门岔,如果不自動安裝future包爱致,請手動安裝。
- 另外還需要安裝typing包寒随。
- 采用豆瓣的源糠悯,可以加快速度。選項 --trusted-host pypi.douban.com 是為了獲得ssl證書的認證
安裝完成之后妻往,采用如下代碼測試安裝是否成功:
import PySimpleGUI27
PySimpleGUI27.main()
(3)測試安裝
安裝成功的話互艾,上面的代碼回產(chǎn)生下圖結(jié)果: