Search code examples
pythonscrollbarpysimplegui

How to change scrollbar color setting in Pysimplegui


I really love the Dark theme of Pysimplegui, but haven't found a way (that I can understand) to change the color of the scrollbar. I read through what I could find on this subject here: https://github.com/PySimpleGUI/PySimpleGUI/issues/3999 and here https://github.com/PySimpleGUI/PySimpleGUI/issues/4994 but I really don't understand it. Could someone please explain to me how to change the green scrollbars to dark gray with the following dark theme example:

import PySimpleGUI as psg
psg.theme('Dark')
psg.set_options(font=("Arial Bold", 14))
toprow = ['S.No.', 'Name', 'Age', 'Marks']
rows = [[1, 'Rajeev', 23, 78],
        [2, 'Rajani', 21, 66],
        [3, 'Rahul', 22, 60],
        [4, 'Robin', 20, 75]]
tbl1 = psg.Table(values=rows, headings=toprow,
   auto_size_columns=True,
   display_row_numbers=False,
   justification='center', key='-TABLE-',
   selected_row_colors='red on yellow',
   enable_events=True,
   expand_x=True,
   expand_y=True,
 enable_click_events=True)
layout = [[tbl1]]
window = psg.Window("Table Demo", layout, size=(715, 200), resizable=True)
while True:
   event, values = window.read()
   print("event:", event, "values:", values)
   if event == psg.WIN_CLOSED:
      break
   if '+CLICKED+' in event:
      psg.popup("You clicked row:{} Column: {}".format(event[2][0], event[2][1]))
window.close()

Solution

  • There're options for the scrollbar of Table element.

    • sbar_trough_color

      Scrollbar color of the trough

    • sbar_background_color

      Scrollbar color of the background of the arrow buttons at the ends AND the color of the "thumb" (the thing you grab and slide). Switches to arrow color when mouse is over

    • sbar_arrow_color

      Scrollbar color of the arrow at the ends of the scrollbar (it looks like a button). Switches to background color when mouse is over

    • sbar_width

      Scrollbar width in pixels

    • sbar_arrow_width

      Scrollbar width of the arrow on the scrollbar. It will potentially impact the overall width of the scrollbar

    • sbar_frame_color

      Scrollbar Color of frame around scrollbar (available only on some ttk themes)

    • sbar_relief

      Scrollbar relief that will be used for the "thumb" of the scrollbar (the thing you grab that slides). Should be a constant that is defined at starting with "RELIEF_" - RELIEF_RAISED, RELIEF_SUNKEN, RELIEF_FLAT, RELIEF_RIDGE, RELIEF_GROOVE, RELIEF_SOLID

    Maybe you can add this option to your Table element.

    sbar_background_color="#707070"
    

    enter image description here