Python Forum
[PySimpleGUI] Tutorial - Name, Address, Phone GUI
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PySimpleGUI] Tutorial - Name, Address, Phone GUI
#11
Following up on the Focus suggestion. Perhaps I should explain how I'm setting focus today.

Focus is set when the first one of these items is found:
  • Button that closes the window - like Submit, OK
  • Single line text input
  • Multi line text input

That seemed like a reasonable algorithm for now. I wanted to focus, but to expose a way to modify in the first version.
Reply
#12
The algorithm is reasonable, but let user decide might be more flexible. Still the SG can step into if user didn't set one
Reply
#13
I didn't go into details/specifics of your project, but maybe you can briefly compare it (e.g. how it is different/better) with other similar projects

easygui
easygui_qt
simplegui

There are also others, that look not actively developed and maintained
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#14
Run the SourceDestFolders() in Demo_Recipes.py, I get an untrimmed 18 characters long 'Destination Folder' displayed correctly although its size was set to (15, 1). Why is it?
Reply
#15
(Aug-05-2018, 08:13 AM)jfong Wrote: Run the SourceDestFolders() in Demo_Recipes.py, I get an untrimmed 18 characters long 'Destination Folder' displayed correctly although its size was set to (15, 1). Why is it?

I'm not sure of this.

When I looked into the code for that example, the width I pass to tk.Label to create the text field indeed has the value '15' despite being able to hold more characters.

Perhaps it could be due to the variable width of characters? Not all 15 characters are alike in that case.
Reply
#16
(Aug-05-2018, 06:08 AM)buran Wrote: I didn't go into details/specifics of your project, but maybe you can briefly compare it (e.g. how it is different/better) with other similar projects

easygui
easygui_qt
simplegui

There are also others, that look not actively developed and maintained

I tried these and more in my quest for a GUI for my Python application. I looked for ANY package that allowed customized forms. Even bad looking forms would do as long as I could include the mix of fields and buttons I wanted. Seeing none that fit my needs, I determined it would be quicker to develop a framework and use that than it would be to code directly to tkinter.

I'm having a difficult time posting the table I made in text format so I'm posting an image of it for now. Will convert into ascii.

[Image: 43689943-a0389a1c-98cf-11e8-8cce-c80f3d8c4b04.jpg]

The biggest differences are:
  • The others are no longer maintained
  • PySimpleGUI includes the features of the others (msgbox, etc) plus the ability to create custom forms easily
  • The look and feel is limited to fonts in the others. PySimpleGUI includes fonts and colors
  • 10 of the major GUI Widget types are in PySimpleGUI. The others have 4 widgets that are used in fixed form definitions

I would also say that the compactness and Python-friendly syntax of PySimpleGUI is superior. It was built to be "in the spirit" of Python development. The others don't have that feeling, to me personally. I think it's a fantastic design that could be a basis for starting a discussion about another GUI interface for Python programmers, particularly beginners. Something needs to be done, at a language level.

If anyone is aware of other Python GUI frameworks that DO allow for custom forms, by all means let me know. I mean something besides the large-scale GUI libraries like Qt and WxPython. Ideally a few lines of code would be all that's required to create a custom GUI.

I was able to recreate EasyGUI's codebox call using a single line of PySimpleGUI code. I don't normally suggest using 1-line solutions, I'm just saying it's possible.

import PySimpleGUI as sg
import easygui   as eg

def codebox(msg, title, text):
    return sg.FlexForm(title).LayoutAndRead([[sg.Multiline(size=(60,4), default_text=msg)],[ sg.Multiline(size=(60,14), default_text=text)], [sg.OK(), sg.Cancel()]])

eg.codebox('msg', 'title', 'test')
codebox('msg', 'title', 'test')
That produced these 2 GUI windows. The first from easyGUI, the second from PySimpleGUI's simulation.
[Image: 43690889-3e2ea6c0-98e0-11e8-866f-efef3aea470f.jpg]

[Image: 43690888-3e04424a-98e0-11e8-8bc9-e21064e8b906.jpg]
Reply
#17
In NonBlockingPeriodicUpdateForm_ContextManager function in file Demo_Recipes.py, the form.CloseNonBlockingForm() was executed when loop finished normally, but not executed at break. Why is it?
Reply
#18
This is the Recipe you are referencing:
# Shows a form that's a running counter
# this is the basic design pattern if you can keep your reading of the
# form within the 'with' block.  If your read occurs far away in your code from the form creation
# then you will want to use the NonBlockingPeriodicUpdateForm example
def NonBlockingPeriodicUpdateForm_ContextManager():
    with sg.FlexForm('Running Timer', auto_size_text=True) as form:
        text_element = sg.Text('', size=(10, 2), font=('Helvetica', 20), text_color='red', justification='center')
        layout = [[sg.Text('Non blocking GUI with updates', justification='center')],
                  [text_element],
                  [sg.T(' ' * 15), sg.Quit()]]
        form.LayoutAndRead(layout, non_blocking=True)

        for i in range(1,500):
            text_element.Update('{:02d}:{:02d}.{:02d}'.format((i // 100) // 60, (i // 100) % 60, i % 100))
            button, values = form.ReadNonBlocking()
            if values is None or button == 'Quit':      # if user closed the window using X
                break
            time.sleep(.01)
        else:
            # if the loop finished then need to close the form for the user
            form.CloseNonBlockingForm()
Your question is about the last line of the code, right? The CloseNonBlockingForm call.

The reason for this is that the Quit button closes the form. If a different button-type has been used, like a ReadFormButton that does not close the form, then a Close form would be required in that instance too. If you would like I can post an example using a button that doesn't close the form.

Here's the same example, except using a different button type which will require the form to be closed.

def NonBlockingPeriodicUpdateForm_ContextManager():
    with sg.FlexForm('Running Timer', auto_size_text=True) as form:
        text_element = sg.Text('', size=(10, 2), font=('Helvetica', 20), text_color='red', justification='center')
        layout = [[sg.Text('Non blocking GUI with updates', justification='center')],
                  [text_element],
                  [sg.T(' ' * 15), sg.ReadFormButton('Quit')]]
        form.LayoutAndRead(layout, non_blocking=True)

        for i in range(1,500):
            text_element.Update('{:02d}:{:02d}.{:02d}'.format((i // 100) // 60, (i // 100) % 60, i % 100))
            button, values = form.ReadNonBlocking()
            if values is None or button == 'Quit':      # if user closed the window using X
                break
            time.sleep(.01)

        form.CloseNonBlockingForm()
Reply
#19
is there a way to override your initial window centering? When you have dual monitors with TV's its not fun searching for the window that you are expecting at (0,0)

Attached Files

Thumbnail(s)
   
Recommended Tutorials:
Reply
#20
(Aug-06-2018, 04:07 PM)metulburr Wrote: is there a way to override your initial window centering? When you have dual monitors with TV's its not fun searching for the window that you are expecting at (0,0)

Yes. There are 2 ways.

You can set location in the FlexForm call. You can also set it globally by calling SetOptions.

form = sg.FlexForm('My Form', location=(0,0))
or

sg.SetOptions(window_location=(0,0))
I'll add something in the documentation about that.
Reply


Forum Jump:

User Panel Messages

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