Home > Net >  Is there a way to visually hold a button after it's been pressed in PySimleGUI?
Is there a way to visually hold a button after it's been pressed in PySimleGUI?

Time:05-24

I want to replace a dropdown with the user clicking an option instead.

I currently have this:

enter image description here

I need this instead: enter image description here

Here's my code (contains pseudocode because I don't know how "deselecting" would work either:

import PySimpleGUI as sg

layout = [

    [ sg.Text("Testing") ],
    [sg.Input(key="in")],

    [ sg.Text ("Language?"), sg.Button("German", key="ger"), sg.Button("French", key="fr")],
]
window = sg.Window("This is for testing purposes", layout)

while True:

    event, values = window.read()

    if event == sg.WINDOW_CLOSED:
        break
    
    if event == "ger":
        deselect("fr") if "fr" is selected
        option = "german"
        ...
    
    if event  == "fr":
        deslect("ger") if "ger" is selected
        option = "french"
        ...

In short, I want to switch from dropdown selection to buttons that show the user that they're currently selecting button X as their option, and if they select another button (button Y), then it would unselect button X and show that button Y is now selected instead.

CodePudding user response:

There's no option indicatoron provided now, but tkinter code will work for it.

Normally a radiobutton displays its indicator. If you set this option to zero, the indicator disappears, and the entire widget becomes a “push-push” indicatoron button that looks raised when it is cleared and sunken when it is set. You may want to increase the borderwidth value to make it easier to see the state of such a control.

import PySimpleGUI as sg

layout = [
    [sg.Text("Testing") ],
    [sg.Input(key="in")],
    [sg.Text ("Language?"),
     sg.Radio("German", "Language", key="ger"),
     sg.Radio("French", "Language", key="fr")],
]
window = sg.Window("This is for testing purposes", layout, finalize=True)
for key in ("ger", "fr"):
    window[key].widget.configure(indicatoron=False)
while True:
    event, values = window.read()
    if event == sg.WINDOW_CLOSED:
        break
window.close()

enter image description here

  • Related