python之PySimpleGUI(三)dome
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的更多相关文章
- 进击的Python【第三章】:Python基础(三)
Python基础(三) 本章内容 集合的概念与操作 文件的操作 函数的特点与用法 参数与局部变量 return返回值的概念 递归的基本含义 函数式编程介绍 高阶函数的概念 一.集合的概念与操作 集合( ...
- Python 基础语法(三)
Python 基础语法(三) --------------------------------------------接 Python 基础语法(二)------------------------- ...
- 笨办法学 Python (第三版)(转载)
笨办法学 Python (第三版) 原文地址:http://blog.sina.com.cn/s/blog_72b8298001019xg8.html 摘自https://learn-python ...
- Python/MySQL(三、pymysql使用)
Python/MySQL(三.pymysql使用) 所谓pymysql就是通过pycharm导入pymysql模块进行远程连接mysql服务端进行数据管理操作. 一.在pycharm中导入pymysq ...
- python学习第三次记录
python学习第三次记录 python中常用的数据类型: 整数(int) ,字符串(str),布尔值(bool),列表(list),元组(tuple),字典(dict),集合(set). int.数 ...
- python中的三种输入方式
python中的三种输入方式 python2.X python2.x中以下三个函数都支持: raw_input() input() sys.stdin.readline() raw_input( )将 ...
- python 历险记(三)— python 的常用文件操作
目录 前言 文件 什么是文件? 如何在 python 中打开文件? python 文件对象有哪些属性? 如何读文件? read() readline() 如何写文件? 如何操作文件和目录? 强大的 o ...
- 3.Python爬虫入门三之Urllib和Urllib2库的基本使用
1.分分钟扒一个网页下来 怎样扒网页呢?其实就是根据URL来获取它的网页信息,虽然我们在浏览器中看到的是一幅幅优美的画面,但是其实是由浏览器解释才呈现出来的,实质它是一段HTML代码,加 JS.CSS ...
- 实操一下<python cookbook>第三版1
这几天没写代码, 练一下代码. 找的书是<python cookbook>第三版的电子书. *这个操作符,运用得好,确实少很多代码,且清晰易懂. p = (4, 5) x, y = p p ...
- python中实现三目运算
python中没有其他语言中的三元表达式,不过有类似的实现方法 如: a = 1 b =2 k = 3 if a>b else 4 上面的代码就是python中实现三目运算的一个小demo, 如 ...
随机推荐
- ARP协议 路由器原理
ARP协议 路由器原理 1 广播与广播域 广播:将广播地址作为目的地址的数据帧 广播域:网络中能够接收到同一个广播所有节点的集合(在这里广播域越小越好) 交换机控制不了广播 路由器可以控制广播 ...
- 学习 vue框架
new watch 监听值的变化 watch: { "input1": { handler(newName, old ...
- div 自动滚轮2
HTML: <div class="cal_bottom" style="height:78%;margin-top:2%;overflow:auto;" ...
- hdu:最大点权(强连通分量kosaraju)
Problem Description给定一个有向图,每个点ii有点权a_iai,请对于每个点ii,找到ii能到达的点中点权的最大值(包括ii点). Input第一行包含一个正整数T(1\leq ...
- 关于nth-of-type的注意事项
普通使用 nth-of-type: <div class="box"> <div> 第一个元素 </div> <p>没有用的元素&l ...
- mybatis的xml中#{}和${}区别
#{}表示一个占位符号,通过#{}可以实现preparedStatement向占位符中设置值,自动进行java类型和jdbc类型转换,#{}可以有效防止sql注入.初步编译后的sql语句是" ...
- pntia7-7 软硬车厢交替排列 (40 分)
7-7 软硬车厢交替排列 (40 分) 设车辆厂生产了硬座车厢和软座车厢共n节(混合在一起),要求使用队列的基本操作,编程实现所有硬座车厢和所有软座车厢交替排列. 例如硬座车厢用H来表示,软座车厢用S ...
- windows消息机制_PostMessage和SendMessage
1.子线程中建立一个窗口 为了在后面比较这两个函数,先使用win32 windows程序中建立子线程,在子线程中建立一个窗口. (1)新建一个 win32 windows应用程序 (2)定义子窗口的窗 ...
- Tomcat总体架构和启动流程
Tomcat大家都知道,这个没什么好描述的,我们先看Tomcat的总体架构 1.总体架构 架构一步一步增加组件,先来个最原始的 === Server:Tomcat的整体服务,负责接收和处理请求.其拥有 ...
- django中使用autocomplete无效查错
检查autocomplete是否工作正常,将自己的结果集注释掉,使用前端预设好的结果集var countries=["Afghanistan","Albania" ...