Home > database >  Vertically aligning sg.slider and text/buttons in PySimpleGUI
Vertically aligning sg.slider and text/buttons in PySimpleGUI

Time:12-15

I can't find any information on how to alter the vertical alignment between the slider and the text/button for the following PySimpleGUI row:

[sg.Text("Threshold:"),
 sg.Slider(range=(0, 255), default_value=0, orientation='h', size=(20, 15), enable_events=True, key="-THRESHOLD-"), 
 sg.Button("Disable Threshold", key="-THRESHOLD_TOGGLE-", size=(14,1))]

It ends up looking like this, which clearly isn't great:

GUI

I'd ideally raise the slider up so that everything except the number is in-line.

I tired using justification='top' for the slider, and justification='bottom' for the text, but neither worked.

Thanks!

CodePudding user response:

Using function sg.vbottom for it, there's also another function sg.vtop for top position.

def vbottom(elem_or_row, expand_x=None, expand_y=None, background_color=None):

Align an element or a row of elements to the bottom of the row that contains it

:param elem_or_row:      the element or row of elements
:type elem_or_row:       Element | List[Element] | Tuple[Element]
:param expand_x:         If True/False the value will be passed to the Column Elements used to make this feature
:type expand_x:          (bool)
:param expand_y:         If True/False the value will be passed to the Column Elements used to make this feature
:type expand_y:          (bool)
:param background_color: Background color for container that is used by vcenter to do the alignment
:type background_color:  str | None
:return:                 A column element containing the provided element aligned to the bottom or list of elements (a row)
:rtype:                  Column | List[Column]
import PySimpleGUI as sg

layout = [
    [sg.Text("Image File"),
     sg.Input(size=5, expand_x=True),
     sg.FileBrowse()],
    [sg.vbottom(sg.Text("Threshold:")),
     sg.Slider(range=(0, 255), default_value=0, orientation='h', size=(20, 15), enable_events=True, key="-THRESHOLD-"),
     sg.vbottom(sg.Button("Disable Threshold", key="-THRESHOLD_TOGGLE-", size=(14,1)))],
]
sg.Window('Title', layout).read(close=True)

enter image description here

  • Related