Python Forum
help with new window
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help with new window
#1
Hello,

I want to do the Math when I click in the first button,but the value is not updating after the second time.
I need to close the window and start again.

See the code below:


import PySimpleGUI as sg    
import sys

def conv_elet(Xmax,Xmin,Ymax,Ymin,Valor):
        Y=(((Valor-Xmin)*(Ymax-Ymin))/(Xmax-Xmin))+Ymin
        return Y

layout1 = [ [sg.Txt('Enter com Speed Ref:'),sg.In(size=(8,1), key='speedref')],      
            [sg.Txt('Enter Speed Conv:'),sg.In(size=(8,1), key='valor')],      
            [sg.Txt('', size=(8,1), key='output')  ],      
            [sg.Button('Calcular', bind_return_key=True)]]     

window1 = sg.Window('Math', layout1)      
     
  
tab1_layout =  [[sg.Button('1- Converter Speed(rpm) para 4-20mA')],
                [sg.Button('2- Converter 4-20mA para Speed(rpm)')],
                [sg.Button('3- Converter Decimal(0-27648) para 4-20mA)')],
                [sg.Button('4- Converter 4-20mA para Decimal(0-27648)')]
               ]


tab2_layout = [[sg.T('This is inside tab 2')],    
               [sg.In(key='in')]]    

layout = [[sg.TabGroup([[sg.Tab('Conversoes Base', tab1_layout, tooltip='tip'), sg.Tab('Conversoes Motores', tab2_layout)]], tooltip='TIP2')]]    
              

window = sg.Window('Tabelas de Conversões', layout, default_element_size=(10,1))    

while True:    
    event, values = window.read()    
    event, values = window1.read()
    
    if event is not None:      
              
            SpeedMax = float(values['speedref']) 
            SpeedMin= SpeedMax * -1
            Ymax=20
            Ymin=4
            Valor1= float(values['valor']) 
            resultado=conv_elet(SpeedMax,SpeedMin,Ymax,Ymin,Valor1)   
            window1['output'].update(resultado)  
           
    else:      
        break       
         
window.close()
Reply
#2
     if event is not None:      
               
            SpeedMax = float(values['speedref']) 
            SpeedMin= SpeedMax * -1
            Ymax=20
            Ymin=4
            Valor1= float(values['valor']) 
            resultado=conv_elet(SpeedMax,SpeedMin,Ymax,Ymin,Valor1)   
            window1['output'].update(resultado)  
            
    else:      
        break       
Your loop ends on the first frame there is no input.
Reply
#3
could you give one suggestion to fix this loop? Thanks a lot
Reply
#4
You might try removing the

else:
    break
You don't need it.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 347 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  tkinter window and turtle window error 1885 3 6,625 Nov-02-2019, 12:18 PM
Last Post: 1885
  update a variable in parent window after closing its toplevel window gray 5 8,978 Mar-20-2017, 10:35 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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