A while ago , When I was writing a source code monitor for my friend , Found a Python The domain is very simple and easy to use GUI library .

Speaking of GUI Libraries , You might think TkInter、PyQt、PyGUI And other popular GUI libraries , I've also tried to use , A very intuitive feeling is , It's too hard to use . Just search the Internet , See if there are any demo, Take it and change it , It turns out that very few , At that time, I gave up learning these graphics libraries , Instead of using vue+flask In the form of browser web page as the program interface , Because I know this , Even if it's a little bit cumbersome to implement , But it's also fast .

A friend may have asked : Do you have to learn the graphical interface ?

Not necessarily , If you write your own programs , Or with other programmers , Then you can call it directly from the command line , There's no need to learn graphical interfaces at all ? When do you want to learn ? If you're going to play games , Or you have to do it for others ( Non-technical personnel ) Writing software tools , So you need to learn the graphical interface . I'm the latter , Occasionally invited to help others write a little tool , So it's much better to have a GUI experience .

Today's library is PySimpleGUI, stay  GitHub Warehouse [1] Yes 5.1K individual star,20 Someone else submitted the code a few days ago , It's very hot .

I read the official documents , Got one demo, It took 2 Hours of time , Yes 56 Line code , You've got a monitoring tool with a graphical interface , as follows :

Want to say PysimpleGUI What attracts me most , Because it has 200 Several sample programs , Almost covering the daily development needs , It can be used with a little modification , It's really convenient .

PysimpleGUI It's encapsulated inside tkinter,Qt(pyside2),wxPython and Remi,Remi For browser support , So it's easy to move your interface to the browser without changing the code . Here's the picture :


And the thing that appeals to me most , It's simple enough , You can build a custom in a few minutes with a few lines of code GUI Layout , Easy enough for beginners , Powerful enough for advanced users . Extensive documentation . Yes 100 A variety of built-in color themes ,200 Several sample programs [2], And it's constantly updated . If you play Raspberry Pi, You can also use this library to write interfaces , You say it's easy to use or not .

Usually a PySimpleGUI The program contains 5 Parts of , See the comments on the code below :

import PySimpleGUI as sg                        # Part 1 -  Import library 

#  Define the contents of the window
layout = [  [sg.Text("What's your name?")],     # Part 2 -  Typesetting
            [sg.Button('Ok')] ]

#  create a window
window = sg.Window('Window Title', layout)      # Part 3 -  Window definition
# Display and interact with the Window
event, values = window.read()                   # Part 4 -  Turn on the main loop  window.read()

# Do something with the information gathered
print('Hello', values[0], "! Thanks for trying PySimpleGUI")

# Finish up by removing from the screen
window.close()  # Part 5 -  close window

Execute the above code , You will get a program as shown in the figure below :