Python Forum
[PySimpleGUI] New GUI Package. Customize with ease
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PySimpleGUI] New GUI Package. Customize with ease
#1
There's a new GUI on the scene!

You'll find PySimpleGUI on PyPI:
pip install --upgrade PySimpleGUI

The GitHub is
https://github.com/MikeTheWatchGuy/PySimpleGUI

It runs on Python3, on the PC, Linux, Mac Raspberry Pi, etc.

It's built on tkinter and has no other dependencies.

[Image: 43366716-38559d1a-9310-11e8-8540-9098656f7372.jpg]

A simple GUI can be built, shown, and have the results directly populated into the caller's variables

[Image: 43417007-df6d8408-9407-11e8-9986-30f0415f08a5.jpg]

That GUI requires this much code:
import PySimpleGUI as sg

form = sg.FlexForm('Rename file or folders', location=(800,800)) # begin with a blank form

layout = [[sg.Text('Rename files or folders')],
[sg.Text('Source for Folders', size=(15, 1)), sg.InputText(), sg.FolderBrowse()],
[sg.Text('Source for Files ', size=(15, 1)), sg.InputText(), sg.FolderBrowse()],
[sg.Submit(), sg.Cancel()]]

button, (folder_path, file_path) = form.LayoutAndRead(layout)


I think this is by far the most Python-like GUI that's currently available.

This may sound pretentious, but is there a formal process for submitting proposals for official new packages to the Python Foundation? I think Python is long overdue something like this.

My source code may not be the prettiest. It's the SDK's interface that I focused on.

If you're in need of a GUI and don't have much time, this is a great option. You can code up a custom GUI in under 10 minutes.

Sorry, got the source code a little wrong and didn't format correctly.

import PySimpleGUI as sg

form = sg.FlexForm('Rename file or folders')  # begin with a blank form

layout = [[sg.Text('Rename files or folders')],
          [sg.Text('Source for Folders', size=(15, 1)), sg.InputText(), sg.FolderBrowse()],
          [sg.Text('Source for Files ', size=(15, 1)), sg.InputText(), sg.FolderBrowse()],
          [sg.Submit(), sg.Cancel()]]

button, (folder_path, file_path) = form.LayoutAndRead(layout)
Reply
#2
Quote:There's a new GUI on the scene!
Not to minimize your work, which looks good.
Since it's a wrapper around tkinter, you should give credit to Fredrik Lundh.
Reply
#3
It's versatile enough to act as a Machine Learning front-end, or a robotic control GUI on a Raspberry Pi.

[Image: 43597426-01aed05e-9650-11e8-8aef-a59c03f5dc32.jpg]

[Image: 43597527-588f0ad8-9650-11e8-81b6-209c01965144.jpg]

It works in synchronous or asynchronous modes.

(Aug-02-2018, 04:33 PM)Larz60+ Wrote:
Quote:There's a new GUI on the scene!
Not to minimize your work, which looks good.
Since it's a wrapper around tkinter, you should give credit to Fredrik Lundh.

I will by all means do just that!

Does that belong in the Readme?

Thanks for the suggestion. Anything to make it better is appreciated.

OK, acknowledgement done. Added Fredrik to the readme and posted to GitHub.
Reply
#4
It should be the other way around. Button gray and hover blue.
Reply
#5
(Aug-02-2018, 05:52 PM)Axel_Erfurt Wrote: It should be the other way around. Button gray and hover blue.

That's no problem. It's a single line of code to configure the defaults. If you want to change button default to that, then call:
sg.SetOptions(button_color=('blue', '#d0d0d0'))
You call it once and it retains the values for all the forms you create.

(Aug-02-2018, 06:16 PM)PySimpleGUI Wrote:
(Aug-02-2018, 05:52 PM)Axel_Erfurt Wrote: It should be the other way around. Button gray and hover blue.
That's no problem. It's a single line of code to configure the defaults. If you want to change button default to that, then call:
sg.SetOptions(button_color=('blue', '#d0d0d0')) 
You call it once and it retains the values for all the forms you create.

However, you're right too. The system default colors should be different than the blue buttons. I'll make a change so that the system default is a possible setting instead of forcing a button color.
Reply
#6
Demo_DuplicateFileFinder.py gives an error on my Mint18(Ubuntu 16.04) on

    msg = f'{total} Files processed\n'\
          f'{dup_count} Duplicates found\n'
Quote: msg = f'{total} Files processed\n'\
^
SyntaxError: invalid syntax

this works for me

    msg = "%s%s%s%s" % (total , ' Files processed\n', dup_count, ' Duplicates found\n')

to see the names of the files

import hashlib
import os
import PySimpleGUI as sg


# ====____====____==== FUNCTION DeDuplicate_folder(path) ====____====____==== #
# Function to de-duplicate the folder passed in                               #
# --------------------------------------------------------------------------- #
def FindDuplicatesFilesInFolder(path):
    shatab = []
    total = 0
    small_count, dup_count, error_count = 0,0,0
    pngdir = path
    dup_files = []
    if not os.path.exists(path):
        sg.MsgBox('Duplicate Finder', '** Folder doesn\'t exist***', path)
        return
    pngfiles = os.listdir(pngdir)
    total_files = len(pngfiles)
    for idx, f in enumerate(pngfiles):
        if not sg.EasyProgressMeter('Counting Duplicates', idx + 1, total_files, 'Counting Duplicate Files'):
            break
        total += 1
        fname = os.path.join(pngdir, f)
        if os.path.isdir(fname):
            continue
        x = open(fname, "rb").read()

        m = hashlib.sha256()
        m.update(x)
        f_sha = m.digest()
        if f_sha in shatab:
            # uncomment next line to remove duplicate files
            # os.remove(fname)
            dup_count += 1
            # sg.Print(f'Duplicate file - {f}')    # cannot current use sg.Print with Progress Meter
            print("Duplicate file:",  f) 
            dup_files.append(f)
            continue
        shatab.append(f_sha)

    msg = "%s%s%s%s%s%s" % (total , ' Files processed\n', dup_count, ' Duplicates found\n', '\nDuplicate Files:\n', '\n'.join(dup_files))
    sg.MsgBox('Duplicate Finder Ended', msg)

# ====____====____==== Pseudo-MAIN program ====____====____==== #
# This is our main-alike piece of code                          #
#   + Starts up the GUI                                         #
#   + Gets values from GUI                                      #
#   + Runs DeDupe_folder based on GUI inputs                    #
# ------------------------------------------------------------- #
if __name__ == '__main__':

    source_folder = None
    rc, source_folder = sg.GetPathBox('Duplicate Finder - Count number of duplicate files', 'Enter path to folder you wish to find duplicates in')
    if rc is True and source_folder is not None:
        FindDuplicatesFilesInFolder(source_folder)
    else:
        sg.MsgBoxCancel('Cancelling', '*** Cancelling ***')
    exit(0)
Reply
#7
DOH!

Sorry about the f-string! Thought I removed all of them.

Thank you so much for pointing it out.

And GREAT to see the post of source code!!
Reply
#8
Can Anyone help ?

How can I get the values from s slider when a slider is moved,
How can I get the values once an item is selected from a ComboBox ?

I would like to write a GUI to create the necessary code for PySimpleGUI !
Reply
#9
(Aug-11-2018, 10:38 PM)heromed Wrote: How can I get the values from s slider when a slider is moved,
How can I get the values once an item is selected from a ComboBox ?

If you are using the latest PySimpleGUI from github, you'll want to download the version I just now uploaded. I broke sliders evidently yesterday.

The return values are either a dictionary or a list depending on how you specified you Elements in your layout. If you used a "key" keyword on any element, then your results will be in dictionary form.

This form has a combobox and a slider:
import PySimpleGUI as sg

with sg.FlexForm('Combo & Slider Demo') as form:
    layout = [
            [sg.Text('Example of a slider and Combobox',font=("Helvetica", 15), text_color='blue')],
            [sg.InputCombo(['Combobox 1', 'Combobox 2'], size=(20, 3))],
            [sg.Slider(range=(1, 100), orientation='h', size=(35, 20), default_value=85)],
            [sg.OK()]
             ]

    button, values = form.LayoutAndRead(layout)

print(values)
This is what the print statement printed:
Output:
['Combobox 1', 85]
I could have written:
button, (combo, slider) = form.LayoutAndRead(layout)
this will populate the variables combo and slider with the values from those 2 fields.
Reply
#10
(Aug-11-2018, 11:38 PM)PySimpleGUI Wrote: If you are using the latest PySimpleGUI from github, you'll want to download the version I just now uploaded. I broke sliders evidently yesterday.
This is why there are branches. So users of given software will always have a stable version to use, and can always use the dev branch if they want the latest features, but with possible bugs.

Currently you only have the master branch. Anytime you upload, you might be potentially breaking it involuntarily without even knowing.
Recommended Tutorials:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PySimpleGUI]Install package on Conda not up-to-date RayJohnson 4 4,386 Jan-22-2020, 11:17 PM
Last Post: RayJohnson

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020