PysimpleGUI,而真正的循环?

时间:2018-12-07 02:14:24

标签: pysimplegui

从PySimpleGUI示例创建了一个简单窗口,并添加了一些按钮。 第一次所有按钮事件都可以正常运行。 问题是它似乎第二次锁定在任何按钮上了吗? 我收到错误消息:

  

回溯(最近通话最近):     文件“ C:\ Python37 \ GUI \ MCC118_Main_01.py”,第51行,在       sg.Print(“按了READ”)     EasyPrint中的文件“ C:\ Python37 \ lib \ site-packages \ PySimpleGUI \ PySimpleGUI.py”,行5121       _easy_print_data.Print(* args,end = end,sep = sep)     打印中的文件“ C:\ Python37 \ lib \ site-packages \ PySimpleGUI \ PySimpleGUI.py”,行5105       self.Close()     关闭文件“ C:\ Python37 \ lib \ site-packages \ PySimpleGUI \ PySimpleGUI.py”,行5108       self.window.Close()   AttributeError:“ NoneType”对象没有属性“ Close”


代码是:

#!/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 个答案:

答案 0 :(得分:1)

这是调试打印中的错误。

获取一个新版本,它将正常工作。

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