0
from ast import Import
from tkinter import Tk

from tkinter import Tk
import  PySimpleGUI as sg

class comparador:

 def main():
    
    layout = [
    [sg.Text("folha 1", justification='left'), sg.Input(key='1')],
    [sg.Text("folha 2", justification='left'), sg.Input(key='2')],
    [sg.Push()],
    [sg.Button("Detetar", key='detetar')]
 ]
   
    
    window = sg.Window("Main Window", layout)
    while True:
        event, values = window.read()
        if event == sg.WIN_CLOSED:
            break
        if event == "detetar":
            window.close()
            folha1 = '1'.split()
            folha2 = '2'.split()
            layout = [[sg.Text(list(set(folha1).symmetric_difference(set(folha2))))]]
        resposta = sg.Window("Second Window", layout, resizable=True)
    choice = None
    while True:
        event, values = resposta.read()
        if event == sg.WIN_CLOSED:
            break
   
    
        
 if __name__ == "__main__":
     main()

Blockquote

Edo Akse
  • 4,051
  • 2
  • 10
  • 21
  • so what is the actual question? You've posted code, and yes, you do have a question in the title, but you need to be a bit more specific in what you want and what is currently happening. See [this excellent article](https://stackoverflow.com/help/how-to-ask) for reference... – Edo Akse Aug 09 '22 at 14:42
  • okay so I need to split the string from the two sg.inputs but I don't know how to do it – CarefulDRAGA Aug 09 '22 at 14:57
  • I tried to use the input key and it didn't work so I want know how can I split the two inputs – CarefulDRAGA Aug 09 '22 at 15:07
  • `folha1 = '1'.split()` does not do what you expect it to do. But again, tell us (by editing the question, not in comments) what it exactly is you expect this to do, and what exact errors you're getting, or exactly what is happening. If you get errors, copy the complete error into the question (by editing the question)... From what I can tell now, it seems that you want to split the [text that is put into](https://stackoverflow.com/a/66171378/9267296) one (or both) of the `sg.Text` elements into separate words? – Edo Akse Aug 09 '22 at 15:13

1 Answers1

0

Using values[key] to get the content of element with key after window.read called and (event, values) returned.

It's better to split the code for different windows.

import  PySimpleGUI as sg

def popup(folha1, folha2):
    sg.theme('DarkBlue4')
    layout = [[sg.Text(list(set(folha1).symmetric_difference(set(folha2))))]]
    resposta = sg.Window("Second Window", layout, resizable=True, finalize=True)
    resposta.force_focus()
    choice = None
    while True:
        event, values = resposta.read()
        if event == sg.WIN_CLOSED:
            break
    resposta.close()

def main():
    sg.theme('DarkBlue3')
    layout = [
        [sg.Text("folha 1", justification='left'), sg.Input(key='INPUT 1')],
        [sg.Text("folha 2", justification='left'), sg.Input(key='INPUT 2')],
        [sg.Push()],
        [sg.Button("Detetar", key='detetar')]
    ]
    window = sg.Window("Main Window", layout)
    while True:
        event, values = window.read()
        if event == sg.WIN_CLOSED:
            break
        elif event == "detetar":
            folha1 = values['INPUT 1'].split()
            folha2 = values['INPUT 2'].split()
            popup(folha1, folha2)
    window.close()

if __name__ == "__main__":
    main()
Jason Yang
  • 11,284
  • 2
  • 9
  • 23