1

Created a simple window from the PySimpleGUI examples and added a few button. The first time all button events works fine. The problem is it seems locked up on any of the buttons the second time? I get the error:

Traceback (most recent call last): File "C:\Python37\GUI\MCC118_Main_01.py", line 51, in sg.Print("READ pressed") File "C:\Python37\lib\site-packages\PySimpleGUI\PySimpleGUI.py", line 5121, in EasyPrint _easy_print_data.Print(*args, end=end, sep=sep) File "C:\Python37\lib\site-packages\PySimpleGUI\PySimpleGUI.py", line 5105, in Print self.Close() File "C:\Python37\lib\site-packages\PySimpleGUI\PySimpleGUI.py", line 5108, in Close self.window.Close() AttributeError: 'NoneType' object has no attribute 'Close'


The code is:

#!/usr/bin/env python
import sys
if sys.version_info[0] >= 3:
    import PySimpleGUI as sg
else:
    import PySimpleGUI27 as sg

#print = sg.Print
sg.ChangeLookAndFeel('TealMono')

# ------ Menu Definition ------ #
menu_def = [['&File', ['&Open', '&Save', 'E&xit', 'Properties']],
            ['&Edit', ['Paste', ['Special', 'Normal', ], 'Undo'], ],
            ['&Help', '&About...'], ]

# ------ Column Definition ------ #
column1 = [[sg.Text('Column 1', background_color='lightblue', justification='center', size=(10, 1))],
           [sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 1')],
           [sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 2')],
           [sg.Spin(values=('Spin Box 1', '2', '3'), initial_value='Spin Box 3')]]

layout = [
    [sg.Menu(menu_def, tearoff=True)],
    [sg.Text('Raspberry Pi MCC118 daqhat', size=(30, 1), justification='center', font=("Helvetica", 25), relief=sg.RELIEF_RIDGE)],
    [sg.Text('Continuous scan Number of Channels (0,1,2,3)?' ),
     sg.Checkbox('0', default=True),sg.Checkbox('1', default=True), sg.Checkbox('2', default=True), sg.Checkbox('3', default=True)],
    [sg.Text('Scan rate ( 1 to 1000 Hz ) ?'), sg.Input('10', do_not_clear=True, size=(5, 1), key='_Scan_'), sg.Text('Test' , key='_ScanOut_')],
    [sg.Text('Hat Addresses ?'), sg.Input('0',do_not_clear=True, size=(5, 1), key='_HatAdd_')],
    [sg.Text('Selected HAT device # : '), sg.InputText('0',do_not_clear=True, size=(5, 1), key='_HatSelect_')],
    #[sg.Text('Output : '), sg.Output('')],
    [sg.Multiline(do_not_clear=True, default_text='Samples Read    Scan Count    Channel 0    Channel 1    Channel 2    Channel 3', size=(75, 10), key='_OUTPUT_')],    
    #[sg.Output( size=(80,10)) ],
    #[sg.InputText('Default Folder'), sg.FolderBrowse()],
    [sg.Button('START', button_color=('white', 'green'), key='_btnSTART_'),
     sg.Button('READ', button_color=('white', 'blue'), key='_btnREAD_'),
     sg.Button('STOP', button_color=('white', 'red'), key='_btnSTOP_')],
    [sg.Button('EXIT', button_color=('black', 'red'), key='_btnEXIT_')]]
    #[sg.Submit(tooltip='Click to submit this form'), sg.Cancel()]]

window = sg.Window('Raspberry Pi MCC118 daqhat', default_element_size=(40, 1), grab_anywhere=False).Layout(layout)

while True:                 # Event Loop  
  ev1, val1 = window.Read()  

  if ev1 == '_btnSTART_':  
      # change the "output" element to be the value of "input" element
      # show the output in the shell display      
      window.FindElement('_ScanOut_').Update(val1['_Scan_'])
      sg.Print("START pressed")
  elif ev1 == '_btnREAD_': 
      sg.Print("READ pressed")
  elif ev1 == '_btnSTOP_':    
      sg.Print("STOP pressed")
  # close window X clicked
  elif ev1 is None or ev1 == '_btnEXIT_':  
      break
  else:
      sg.Print("NO event")
  sg.Print(ev1, val1)

window.Close()
1
  • can sg.Print() print list? because variable val1 is a list. Can be problem there? Try comment last Print above window.Close() Commented Dec 7, 2018 at 5:51

1 Answer 1

2

It was a bug in the debug print.

Get a new version and it'll work fine.

pip install --upgrade --no-cache-dir PySimpleGUI

Sign up to request clarification or add additional context in comments.

4 Comments

That did it ! Upgraded from 3.14 to 3.17 Nice work. I spent 9 hours loading wxpython for Raspberry Pi yours is a much simpler and elegant solution.
Sorry about the bug. It's rare, but does happen. Glad it's going to work out for you. I'm sure you're going to find it quite enjoyable to code now.
Please post the information on the GitHub. We can have a conversation there. This isn't the place.
It's clear your Raspberry Pi did not pick up the new version. This crash is only when you close the debug window, right? It's not a critical operation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.