dome1第一个程序
其实会了第一个程序后面基本就都通了,就这么简单,后面只需要注意一下细节就可以
import PySimpleGUI as sg

sg.theme('Dark Blue 3') # please make your creations colorful

# All the stuff inside your window. This is the PSG magic code compactor...这个也就是布局,线性布局,挺简单
layout = [ [sg.Text('Some text on Row 1')],
[sg.Text('Enter something on Row 2'), sg.InputText()],
[sg.OK(), sg.Cancel()]]

# Create the Window
window = sg.Window('Window Title', layout)实例化,窗口不会出现
# Event Loop to process "events"
while True: 循环
event, values = window.read()获取事件结果是个字典
if event in (sg.WIN_CLOSED, 'Cancel'):
break
window['key'].update('压我改变的值')通过键来修改值
window.close() 窗口关闭

2 dome2 2个窗口,并且都是活动的
# Design pattern 2 - First window remains active

layout = [[ sg.Text('Window 1'),],
[sg.Input(do_not_clear=True)],
[sg.Text(size=(15,1), key='-OUTPUT-')],
[sg.Button('Launch 2'), sg.Button('Exit')]]

win1 = sg.Window('Window 1', layout)

win2_active = False
while True:
ev1, vals1 = win1.read(timeout=100)
win1['-OUTPUT-'].update(vals1[0])
if ev1 == sg.WIN_CLOSED or ev1 == 'Exit':
break

if not win2_active and ev1 == 'Launch 2':
win2_active = True
#win1.Hide()窗口1隐藏
layout2 = [[sg.Text('Window 2')],
[sg.Button('Exit')]]

win2 = sg.Window('Window 2', layout2)

if win2_active:
ev2, vals2 = win2.read(timeout=100)
if ev2 == sg.WIN_CLOSED or ev2 == 'Exit':
win2_active = False
win2.close()
#win1.UnHide()窗口1出现

dome3

this one long import has the effect of making the code more compact as there is no 'sg.' prefix required for Elements
import PySimpleGUI as sg
from PySimpleGUI import InputCombo, Combo, Multiline, ML, MLine, Checkbox, CB, Check, Button, B, Btn, ButtonMenu, Canvas, Column, Col, Combo, Frame, Graph, Image, InputText, Input, In, Listbox, LBox, Menu, Multiline, ML, MLine, OptionMenu, Output, Pane, ProgressBar, Radio, Slider, Spin, StatusBar, Tab, TabGroup, Table, Text, Txt, T, Tree, TreeData, VerticalSeparator, Window, Sizer

"""
Demo Columns and Frames
Demonstrates using mixture of Column and Frame elements to create a nice window layout.
A couple of the concepts shown here include:
* Using Columns and Frames with specific sizes on them
* Importing all required classes so that "sg." is not required on any objects. This makes the code more compact and readable

There are 3 columns. Two are side by side at the top and the third is along the bottom
"""

sg.theme('GreenTan')

col2 = Column([[Frame('Accounts:', [[Column([[Listbox(['Account '+str(i) for i in range(1, 16)],
key='-ACCT-LIST-', size=(15, 20)), ]], size=(150, 400))]])]], pad=(0, 0))

col1 = Column([
# Categories frame
[Frame('Categories:', [[ Radio('Websites', 'radio1', default=True, key='-WEBSITES-', size=(10, 1)),
Radio('Software', 'radio1', key='-SOFTWARE-', size=(10, 1))]],)],
# Information frame
[Frame('Information:', [[Text(), Column([[Text('Account:')],
[Input(key='-ACCOUNT-IN-', size=(19, 1))],
[Text('User Id:')],
[Input(key='-USERID-IN-', size=(19, 1)),
Button('Copy', key='-USERID-')],
[Text('Password:')],
[Input(key='-PW-IN-', size=(19, 1)),
Button('Copy', key='-PASS-')],
[Text('Location:')],
[Input(key='-LOC-IN-', size=(19, 1)),
Button('Copy', key='-LOC')],
[Text('Notes:')],
[Multiline(key='-NOTES-', size=(25, 5))],
], size=(235, 350), pad=(0, 0))]])], ], pad=(0, 0))

col3 = Column([[Frame('Actions:', [[Column([[Button('Save'), Button(
'Clear'), Button('Delete'), ]], size=(450, 45), pad=(0, 0))]])]], pad=(0, 0))

layout = [[col1, col2], [col3]]

window = Window('Passwords', layout)

while True:
event, values = window.read()
print(event, values)
if event == sg.WIN_CLOSED:
break

window.close()

python之PySimpleGUI(三)dome的更多相关文章

  1. 进击的Python【第三章】:Python基础(三)

    Python基础(三) 本章内容 集合的概念与操作 文件的操作 函数的特点与用法 参数与局部变量 return返回值的概念 递归的基本含义 函数式编程介绍 高阶函数的概念 一.集合的概念与操作 集合( ...

  2. Python 基础语法(三)

    Python 基础语法(三) --------------------------------------------接 Python 基础语法(二)------------------------- ...

  3. 笨办法学 Python (第三版)(转载)

    笨办法学 Python (第三版) 原文地址:http://blog.sina.com.cn/s/blog_72b8298001019xg8.html   摘自https://learn-python ...

  4. Python/MySQL(三、pymysql使用)

    Python/MySQL(三.pymysql使用) 所谓pymysql就是通过pycharm导入pymysql模块进行远程连接mysql服务端进行数据管理操作. 一.在pycharm中导入pymysq ...

  5. python学习第三次记录

    python学习第三次记录 python中常用的数据类型: 整数(int) ,字符串(str),布尔值(bool),列表(list),元组(tuple),字典(dict),集合(set). int.数 ...

  6. python中的三种输入方式

    python中的三种输入方式 python2.X python2.x中以下三个函数都支持: raw_input() input() sys.stdin.readline() raw_input( )将 ...

  7. python 历险记(三)— python 的常用文件操作

    目录 前言 文件 什么是文件? 如何在 python 中打开文件? python 文件对象有哪些属性? 如何读文件? read() readline() 如何写文件? 如何操作文件和目录? 强大的 o ...

  8. 3.Python爬虫入门三之Urllib和Urllib2库的基本使用

    1.分分钟扒一个网页下来 怎样扒网页呢?其实就是根据URL来获取它的网页信息,虽然我们在浏览器中看到的是一幅幅优美的画面,但是其实是由浏览器解释才呈现出来的,实质它是一段HTML代码,加 JS.CSS ...

  9. 实操一下<python cookbook>第三版1

    这几天没写代码, 练一下代码. 找的书是<python cookbook>第三版的电子书. *这个操作符,运用得好,确实少很多代码,且清晰易懂. p = (4, 5) x, y = p p ...

  10. python中实现三目运算

    python中没有其他语言中的三元表达式,不过有类似的实现方法 如: a = 1 b =2 k = 3 if a>b else 4 上面的代码就是python中实现三目运算的一个小demo, 如 ...

随机推荐

  1. react修改静态文件根目录

    .env(项目根目录环境变量文件) PUBLIC_URL:http://cdn.com/

  2. midway 框架学习

    最近 和别人一块运维 开源 产品,后台需要用到 midway框架,所以进行学习. 首先就是midway的搭建, 首先 npm init midway ,初始化项目,选择 koa-v3 template ...

  3. Python测试——安装篇总结

    测试用到的工具自己知道的有: 写脚本类:sublime  ,PyCharm,Eclipse+PyDev,目前我知道的只有这么多,大家知道的肯定还有很多,欢迎留言哈 录制脚本类:火狐自带的seleniu ...

  4. JVM-创建一个对象的详细过程

    Person person=new Person(): 1.现在栈中申请一个自己的栈空间 2.类加载检查 每当使用new操作符创建一个对象时,类加载器都会从常量池中寻找该对象的符号引用,如果找到,则根 ...

  5. ES搜索高亮分词排序聚合搜索

    分词高亮搜索代码 List<A> list = new ArrayList<>(); //设置高亮显示 HighlightBuilder highlightBuilder = ...

  6. 如何通过dump文件定位崩溃,解决问题

    1.dump文件是附加堆栈信息的存储文件的简称,文件扩展名".dmp",通过dump文件我们可以得到程序运行某一时刻的堆栈数据.2.当程序意外崩溃后,通常程序会立即中断运行,拿到这 ...

  7. 问题:fatal: unable to access 'https://github.com/XXXXX': GnuTLS recv error (-110): The TLS connection was non-properly terminated.

    问题:fatal: unable to access 'https://github.com/XXXXX': GnuTLS recv error (-110): The TLS connection ...

  8. loadrunner入门(关联)

    左右边界:提取第一个id web_reg_save_param_ex(                 "ParamName=Id",         "LB=//OK[ ...

  9. python print 一个进度条

    import time scale=100 print("执行开始".center(scale+28,'-')) start = time.perf_counter() for i ...

  10. 动态生成frame时需要对frame类进行注册,否则会出现找不到frame类的错误。

    procedure TMainForm.openFram(Caption, FormClassName, imgIdx: string); var i: integer; sheet: TUniTab ...