Python Forum

Full Version: VBA function convert to python by PysimpleGUI
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi All,

Tried to use PysimpleGUI instead of VBA could not do it, please help me check out it, thanks in advance!

Selected file pick up what I want column data and subtract with Target median value get delta then check delta whether in range or not,paint different background color to Text control.
If delta>=0.1 paint background color green.
If delta>=0.2 paint background color pink.
If delta>=0.3 paint background color red.

Last update delta value in each text control(1-35).

The VBA code and check file is attached for your reference.


import PySimpleGUI as sg
import pandas as pd
import os

working_directory=os.getcwd()

Standard_median=-38.1

sg.theme('Dark Brown 1')

headings = [['1]', '2]', '3]','4]','5]','6]','7]'],
            ['8]', '9]', '10]','11]','12]','13]','14]'],
            ['15]', '16]', '17]', '18]', '19]', '20]', '21]'],
            ['22]', '23]', '24]', '25]', '26]', '27]', '28]'],
            ['29]', '30]', '31]', '32]', '33]', '34]', '35]'],]
header =  [[sg.Text(headings[row][col],size=(10,5),font=("Helvetica", 15),background_color='white',text_color='red')for col in range(7)] for row in range(5)]

BNT=[
     [sg.Text('Selected File')],
     [sg.InputText(key="-FILE_PATH-"),
     sg.FilesBrowse(initial_folder=working_directory,file_types=[("CSV Files", "*.csv")])],
     [sg.OK('Check Master',key='OK',size=(10,2)),sg.Exit(size=(10,2))]
     ]


input_rows = [[sg.Input(size=(15,1), pad=(0,0)) for col in range(4)] for row in range(10)]


layout=BNT+header

window = sg.Window('Master Check',layout,font='Courier 12')

def read_csv(csv_add):
  df=pd.read_csv(csv_add,usecols=[597,598,599,600,601,602,603,604,605,606,607,608,609,610,611,612,613,614,615,616,617,618,619,620,621,622,623,624,625,
                                  626,627,628,629,630,631])
  tt=df.values[-1].astype('float')-Standard_median
  return tt

while True:
    event,value = window.read()
    if event in (sg.WIN_CLOSED,'Exit'):
        break
    elif event == "OK":
        csv_add=value["-FILE_PATH-"]
        print(read_csv(csv_add))

window.close()
Who can help me for the matter. My purpose is click button select *.csv pick up specific column data updated in Text control and compared value in which level then paint different background color with text control.

In other words, how to dynamic updated data in each text control(35 sites) and compared then paint color.