table grid lines and column colors in PySimpleGui

1.4k views Asked by At

I'm designing an app with PySimpleGui, and I want to create a table that looks something like this:

enter image description here

I was able to create a table with the appropriate column headings, but I can't find anything in the docs about how to display grid lines or set the background color for individual columns. Is there a way to do this?

1

There are 1 answers

1
Abel Avalos On
  1. import PySimpleGUI as sg

     sg.theme('DefaultNoMoreNagging')
    
     Sheet=[] menu_opt=[
                 ['&File',['&New','&Save','&Clear','E&xit']],
                 ['&Edit',['&Undo','C&opy','&Paste']]
                 ]
    
     menu=[sg.Menu(menu_opt)]
    
     Sheet.append(menu)
    
     AZ='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    
     headers=[sg.T(L,size=(5,1),relief='raised',enable_events
     =True,k=str(L)) for L in AZ]
    
     for r in range(0,30):
         Sheet.append([sg.I(size=(5,1),background_color='White',k=str(L)+str(r))
     for L in AZ])
    
     layout=[
             headers,
             [sg.Column(Sheet,scrollable=True)],
             [sg.StatusBar('Sheet 1')]
             ]
    
     window=sg.Window('SpreadSheet',layout,element_padding=0,size=(600,370))
    
     while True:
         event,values=window.read()
    
         if event==sg.WIN_CLOSED or event=='Exit':
             break
         if event:
             for r in range(0,30):
                 window[event+str(r)].update(background_color='Yellow')
    
     window.close()