神器 PySimpleGUI 初体验

PySimpleGUI是一个便捷的Python GUI库,适用于快速创建界面。通过简单的安装和经典例程,开发者能在几分钟内实现GUI。官方手册提供了详细教程,包括安装和基础用法。
摘要由CSDN通过智能技术生成

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 
  • 5
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
PySimpleGUI是一个基于tkinter的GUI库,它被设计成足够简单、方便、pythonic。它的主要目的是帮助Python开发者更轻松地创建图形用户界面PySimpleGUI提供了一种简洁而直观的方式来构建GUI应用程序,无论是初学者还是有经验的开发者都可以很容易地上手使用。 PySimpleGUI的官方网站提供了详细的教程和示例代码,可以让你更加深入地了解和学习如何使用这个库来创建GUI应用程序。你可以在官方网站的文档部分找到一份案例,这些案例可以帮助你学习各种不同类型的GUI界面的创建和设计。 在使用PySimpleGUI之前,值得注意的是,默认情况下,PySimpleGUI只支持PNG、GIF等格式的图片,无法调用常见的JPG和TIFF格式。但是你可以使用Python中的另一个库Pillow来进行格式转换,以便在PySimpleGUI中使用JPG和TIFF格式的图片。 总的来说,PySimpleGUI是一个简单易用的GUI库,它提供了丰富的功能和灵活的设计方式,使得Python开发者可以更加轻松地创建各种类型的GUI应用程序。如果你是一个Python小彩笔,想要写一个GUI应用程序,尝试使用PySimpleGUI可能会是一个不错的选择。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [一文解决pythonGUI--python程序员必会GUI库-神器PySimpleGUI良心总结](https://blog.csdn.net/realliyuhao/article/details/104587152)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [PySimpleGUI 进阶| 原来用Python做一个图片查看系统,还能这么简单!](https://blog.csdn.net/weixin_41846769/article/details/110306785)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值