PySimpleGUI 什么时候有用呢?显然,是你需要 GUI 的时候。仅需不超过 5 分钟,就可以让你创建并尝试 GUI。最便捷的 GUI 创建方式就是从 PySimpleGUI 经典实例中拷贝一份代码============》直接看下面的例程就可以了
- 使用手册(官方手册)==》https://pysimplegui.readthedocs.io/en/latest/cookbook/
- 安装
pip install pysimplegui
or
pip3 install pysimplegui
或者自己下载,链接:PyPI
以下就是初次体验的例程
#!usr/bin/env python
# -*-coding:utf-8 -*-
# @Time :2019/10/15 17:14
# @Author :xxx
# @File :1-体验.py
# description:
# @SoftWare :PyCharm Community Edition
import PySimpleGUI as sg
def test_1():
'''
简单测试PySimpleGUI
:return:
'''
# All the stuff inside your window.=================1
layout = [
[sg.Text('some text on row1')],
[sg.Text('enter something on row2'), sg.InputText()],
[sg.Button('ok'), sg.Button('cancel')],
]
# Create the Window=================================2
window = sg.Window('window titel', layout=layout)
# Event Loop to process "events" and get the "values" of the inputs
while True:
event, values = window.read() #====================3
# if user closes window or clicks cancel
if event in (None, 'cancel'):
break;
print('you entered:', values[0])
window.close()
def test_2():
'''
测试 PySimpleGUI 排版
:return:
'''
layout = [
[sg.Text('Please enter your Name, Address, Phone')],
[sg.Text('Name', size=(15, 1)), sg.InputText('name')],
[sg.Text('Address', size=(15, 1)), sg.InputText('address')],
[sg.Text('Phone', size=(15, 1)), sg.InputText('phone')],
[sg.Submit(), sg.Cancel()]
]
# Create the Window
window = sg.Window('window titel', layout=layout)
button, values = window.read()
print(button, values[0], values[1], values[2])
def test_3():
'''
基本的GUI 组件
:return:
'''
# 外观
sg.ChangeLookAndFeel('GreenTan')
# All the stuff inside your window.=================1
column1