PySimpleGUI / PySimpleGUI

Python GUIs for Humans! PySimpleGUI is the top-rated Python application development environment. Launched in 2018 and actively developed, maintained, and supported in 2024. Transforms tkinter, Qt, WxPython, and Remi into a simple, intuitive, and fun experience for both hobbyists and expert users.

Home Page:https://www.PySimpleGUI.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question] set the default button popup_yes_no to no

lastrocer opened this issue · comments

Type of Issue (Enhancement, Error, Bug, Question)

Question


Environment

Operating System

Windows version 10

PySimpleGUI Port (tkinter, Qt, Wx, Web)

tkinter


Versions

Python version (sg.sys.version)

3.7.8 (tags/v3.7.8:4b47a5b6ba, Jun 28 2020, 08:53:46) [MSC v.1916 64 bit (AMD64)]

PySimpleGUI Version (sg.__version__)

4.60.3

GUI Version (tkinter (sg.tclversion_detailed), PySide2, WxPython, Remi)

8.6.9


Your Experience In Months or Years (optional)

Years Python programming experience
Years Programming experience overall
No Have used another Python GUI Framework? (tkinter, Qt, etc) (yes/no is fine)


Troubleshooting

These items may solve your problem. Please check those you've done by changing - [ ] to - [X]

  • Searched main docs for your problem www.PySimpleGUI.org
  • Looked for Demo Programs that are similar to your goal Demos.PySimpleGUI.org
  • If not tkinter - looked for Demo Programs for specific port
  • For non tkinter - Looked at readme for your specific port if not PySimpleGUI (Qt, WX, Remi)
  • Run your program outside of your debugger (from a command line)
  • Searched through Issues (open and closed) to see if already reported Issues.PySimpleGUI.org
  • Tried using the PySimpleGUI.py file on GitHub. Your problem may have already been fixed but not released

Detailed Description

set popup_yes_no default button to no

Code To Duplicate

import PySimpleGUI as sg
sg.popup_yes_no("Can you set the default button to No?",  title="YesNo")

Screenshot, Sketch, or Drawing

There're lot of settings for a popup, but no default to "No" button.
Basically, you can build one by yourself if you need something special or different.

Example Code

import PySimpleGUI as sg

def popup_yes_no(text, title):
    layout = [
        [sg.Text(text)],
        [sg.Button("Yes"), sg.Button("No", bind_return_key=True)]
    ]
    window = sg.Window(title, layout, finalize=True)
    window["No"].set_focus()
    button, values = window.read(close=True)
    return button

popup_yes_no("Can you set the default button to No?",  title="YesNo")

image

Thank you very much. I am happy to see PysimpleGUI the company and the software keep getting stronger and better.

Thank you so very much for the encouragement @lastrocer .... we're trying ....

For your popup, I think Jason's got the right idea.

You can also use the custom_text parameter to popup and reverse the order to "No", "Yes". This will cause "No" to get focus... but there is a problem at the moment with focus in these popups so Jason's technique is the best.