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, 如 ...
随机推荐
- Jmeter一、开源软件的崛起
一.jmeter自身特点: 1.开源,轻量级,更适合自动化和持续集成. 2.学习难度大. 3.资料少.多英文. 二.性能测试工具选型的原则 1.成本: a.工具成本 b.学习成本 2.通信协议: a. ...
- Alibaba Cloud Linux 3.2104 64位安装php7.2.12
1 安装php所需要的扩展 yum -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel curl curl ...
- curl 查看响应时间
curl -o /dev/null -s -w "time_namelookup:%{time_namelookup}\ntime_connect: %{time_connect}\ntim ...
- win10 wampserver升级 php7.0至 php7.2
1.去官网下载php7.2 下载地址: https://windows.php.net/download#php-7.0 2.下载安装 visual c++ 2017 或 visual c++ 20 ...
- intellij idea修改背景图片
上方菜单栏选择 File -> settings -> plugins,搜索Backgroung Image Plus插件 下载之后restart 菜单栏上选择view 设置好后选择O ...
- 获取指定网卡的ip
#!/usr/bin/env python # -*- coding: utf-8 -*- import socket import fcntl import struct def get_ip_ad ...
- 表单笔记-Antd(Form)
antd表单使用笔记 import React, { useState, useEffect, useRef } from "react"; import { Form, Inpu ...
- 线程Thread小记
1 public class ConcurentDemo extends Thread { 2 @Override 3 public void run() { 4 super.run(); 5 Sys ...
- mysql 排序ROW_NUMBER() RANK() DENSE_RANK()
with 月业绩 as (SELECT 年份,月份, ROUND(sum(总业绩)/100000) 业绩 FROM `myj` group by 年份,月份) select * ,ROW_NUMBER ...
- 狂神说SpringBoot笔记之编写一个http接口
编写一个http接口 1.1.在主程序的同级目录下,新建一个controller包,一定要在同级目录下,否则识别不到 2.代码 1 package com.example.app01.demo.api ...