0
import PySimpleGUI as sg

#sg.theme('DarkBrown7')

layout = [

    [sg.Text('Medico Refertatore', size=(15, 1)), sg.InputText()],
    [sg.Text('Nome Paziente', size=(15, 1)), sg.InputText()],
    [sg.Text('Cognome Paziente', size=(15, 1)), sg.InputText()],
    [sg.Text('j', size=(15, 1)), sg.Button('0', focus = True ), sg.Button('1-24%', focus = True), sg.Button('25-49%', focus = True), sg.Button('50-69%', focus = True), sg.Button('70-99%', focus = True), sg.Button('100%', focus = True), ],
    [sg.Text('a', size=(15, 1)), sg.Button('0', focus = True ), sg.Button('1-24%', focus = True), sg.Button('25-49%', focus = True), sg.Button('50-69%', focus = True), sg.Button('70-99%', focus = True), sg.Button('100%', focus = True), ],
    [sg.Text('b', size=(15, 1)), sg.Button('0', focus = True ), sg.Button('1-24%', focus = True), sg.Button('25-49%', focus = True), sg.Button('50-69%', focus = True), sg.Button('70-99%', focus = True), sg.Button('100%', focus = True), ],
    [sg.Text('c', size=(15, 1)), sg.Button('0', focus = True ), sg.Button('1-24%', focus = True), sg.Button('25-49%', focus = True), sg.Button('50-69%', focus = True), sg.Button('70-99%', focus = True), sg.Button('100%', focus = True), ],
    [sg.Text('d', size=(15, 1)), sg.Button('0', focus = True ), sg.Button('1-24%', focus = True), sg.Button('25-49%', focus = True), sg.Button('50-69%', focus = True), sg.Button('70-99%', focus = True), sg.Button('100%', focus = True), ],
    [sg.Text('e', size=(15, 1)), sg.Button('0', focus = True ), sg.Button('1-24%', focus = True), sg.Button('25-49%', focus = True), sg.Button('50-69%', focus = True), sg.Button('70-99%', focus = True), sg.Button('100%', focus = True), ],
    [sg.Text('f', size=(15, 1)), sg.Button('0', focus = True ), sg.Button('1-24%', focus = True), sg.Button('25-49%', focus = True), sg.Button('50-69%', focus = True), sg.Button('70-99%', focus = True), sg.Button('100%', focus = True), ],
    [sg.Text('g', size=(15, 1)), sg.Button('0', focus = True ), sg.Button('1-24%', focus = True), sg.Button('25-49%', focus = True), sg.Button('50-69%', focus = True), sg.Button('70-99%', focus = True), sg.Button('100%', focus = True), ],
    [sg.Text('h', size=(15, 1)), sg.Button('0', focus = True ), sg.Button('1-24%', focus = True), sg.Button('25-49%', focus = True), sg.Button('50-69%', focus = True), sg.Button('70-99%', focus = True), sg.Button('100%', focus = True), ],
    [sg.Text('i', size=(15, 1)), sg.Button('0', focus = True ), sg.Button('1-24%', focus = True), sg.Button('25-49%', focus = True), sg.Button('50-69%', focus = True), sg.Button('70-99%', focus = True), sg.Button('100%', focus = True), ],
    [sg.Text('l', size=(15, 1)), sg.Button('0', focus = True ), sg.Button('1-24%', focus = True), sg.Button('25-49%', focus = True), sg.Button('50-69%', focus = True), sg.Button('70-99%', focus = True), sg.Button('100%', focus = True), ],
    [sg.Text('m', size=(15, 1)), sg.Button('0', focus = True ), sg.Button('1-24%', focus = True), sg.Button('25-49%', focus = True), sg.Button('50-69%', focus = True), sg.Button('70-99%', focus = True), sg.Button('100%', focus = True), ],
    [sg.Text('n', size=(15, 1)), sg.Button('0', focus = True ), sg.Button('1-24%', focus = True), sg.Button('25-49%', focus = True), sg.Button('50-69%', focus = True), sg.Button('70-99%', focus = True), sg.Button('100%', focus = True), ],
    [sg.Text('o', size=(15, 1)), sg.Button('0', focus = True ), sg.Button('1-24%', focus = True), sg.Button('25-49%', focus = True), sg.Button('50-69%', focus = True), sg.Button('70-99%', focus = True), sg.Button('100%', focus = True), ],
    [sg.Text('p', size=(15, 1)), sg.Button('0', focus = True ), sg.Button('1-24%', focus = True), sg.Button('25-49%', focus = True), sg.Button('50-69%', focus = True), sg.Button('70-99%', focus = True), sg.Button('100%', focus = True), ],
    [sg.Text('q', size=(15, 1)), sg.Button('0', focus = True ), sg.Button('1-24%', focus = True), sg.Button('25-49%', focus = True), sg.Button('50-69%', focus = True), sg.Button('70-99%', focus = True), sg.Button('100%', focus = True), ],
    [sg.Text('r', size=(15, 1)), sg.Button('0', focus = True ), sg.Button('1-24%', focus = True), sg.Button('25-49%', focus = True), sg.Button('50-69%', focus = True), sg.Button('70-99%', focus = True), sg.Button('100%', focus = True), ],
    [sg.Text('s', size=(15, 1)), sg.Button('0', focus = True ), sg.Button('1-24%', focus = True), sg.Button('25-49%', focus = True), sg.Button('50-69%', focus = True), sg.Button('70-99%', focus = True), sg.Button('100%', focus = True), ],
    [sg.Text('t', size=(15, 1)), sg.Button('0', focus = True ), sg.Button('1-24%', focus = True), sg.Button('25-49%', focus = True), sg.Button('50-69%', focus = True), sg.Button('70-99%', focus = True), sg.Button('100%', focus = True), ],
    [sg.Text('u', size=(15, 1)), sg.Button('0', focus = True ), sg.Button('1-24%', focus = True), sg.Button('25-49%', focus = True), sg.Button('50-69%', focus = True), sg.Button('70-99%', focus = True), sg.Button('100%', focus = True), ],
    [sg.Text('v', size=(15, 1)), sg.Button('0', focus = True ), sg.Button('1-24%', focus = True), sg.Button('25-49%', focus = True), sg.Button('50-69%', focus = True), sg.Button('70-99%', focus = True), sg.Button('100%', focus = True), ],
    [sg.Text('z', size=(15, 1)), sg.Button('0', focus = True ), sg.Button('1-24%', focus = True), sg.Button('25-49%', focus = True), sg.Button('50-69%', focus = True), sg.Button('70-99%', focus = True), sg.Button('100%', focus = True), ],
    [sg.Submit(), sg.Cancel()]

]

window = sg.Window('APP RICERCA', layout)

while True:
    event, values = window.read()

    if event in (None,'Cancel'):   # if user closes window or clicks cancel
        break

    elif event == '0':
        print('1')
    elif event == '1-24%':
        print('2')  
    elif event == '25-49%':
        print('3')
    elif event == '50-69%':
        print('4') 
    elif event == '70-99%':
        print('5')      
    elif event == '100%':
        print('6')



window.close()

I wrote this code above here but I am unable to make it run for every row. Just for the first one. How so and how will I be able to solve the issue?

martineau
  • 119,623
  • 25
  • 170
  • 301
VegaOmega
  • 19
  • 1
  • 7

1 Answers1

0

PySimpleGUI addes a suffex at the end of duplicate object names, which is why == does not work, replace it with .startswith() as follows:

import PySimpleGUI as sg

sg.theme('DarkBrown7')
layout = [

[sg.Text('Medico Refertatore', size=(15, 1)), sg.InputText()],
[sg.Text('Nome Paziente', size=(15, 1)), sg.InputText()],
[sg.Text('Cognome Paziente', size=(15, 1)), sg.InputText()],
[sg.Text('j', size=(15, 1)), sg.Button('0', focus = True ), sg.Button('1-24%', focus = True), sg.Button('25-49%', focus = True), sg.Button('50-69%', focus = True), sg.Button('70-99%', focus = True), sg.Button('100%', focus = True), ],
...

[sg.Text('z', size=(15, 1)), sg.Button('0', focus = True ), sg.Button('1-24%', focus = True), sg.Button('25-49%', focus = True), sg.Button('50-69%', focus = True), sg.Button('70-99%', focus = True), sg.Button('100%', focus = True), ],
[sg.Submit(), sg.Cancel()]
]

window = sg.Window('APP RICERCA', layout)

while True:
    event, values = window.read()    
    if event in (None,'Cancel'):   # if user closes window or clicks cancel
        break

    elif event.startswith('0'):
        print('1')
    elif event.startswith('1-24%'):
        print('2')  
    elif event.startswith('25-49%'):
        print('3')
    elif event.startswith('50-69%'):
        print('4') 
    elif event.startswith('70-99%'):
        print('5')      
    elif event.startswith('100%'):
        print('6')
    else:
        print(event)
window.close()