How To Minimize Window Using Python/PySimpleGUI

Question:

Dears,

How To Minimize Window Using Python/PySimpleGUI ?
Knowing that , I want to hide existing title bar from my Window and add my personal icons :Maximize, Minimize and Close, it’s OK for 2 and not the case for Minimize.

I followed answer shared in : How to create a minimize button with pysimplegui?, unfortunately didn’t help , it’s behavying same as Close button.

if event == "Button":

  window.close()

Could you please support on that ?

Asked By: Hacene2022

||

Answers:

Check the document on https://www.pysimplegui.org/en/latest/ all the time.

import PySimpleGUI as sg

sg.PySimpleGUI.SYMBOL_TITLEBAR_MINIMIZE = '.'
sg.PySimpleGUI.SYMBOL_TITLEBAR_MAXIMIZE = 'O'
sg.PySimpleGUI.SYMBOL_TITLEBAR_CLOSE    = 'x'

layout = [
    [sg.Titlebar(
        title='TITLE',
        icon=sg.EMOJI_BASE64_HAPPY_IDEA,
        text_color='white',
        background_color='blue',
        font=('Courier New', 40, 'bold'),
    )],
    [sg.Button('Minimize'), sg.Button('Exit')],
]

window = sg.Window('Title', layout, finalize=True,
    # use_custom_titlebar=True,
    # titlebar_background_color='blue',
    # titlebar_text_color='white',
    # titlebar_font=('Courier New', 40, 'bold'),
    # titlebar_icon=sg.EMOJI_BASE64_HAPPY_IDEA,
)

while True:

    event, values = window.read()

    if event in (sg.WIN_CLOSED, 'Exit'):
        break
    elif event == 'Minimize':
        window.minimize()

window.close()

The buttons for minimize, maximize and close button of a window are defined as Text elements. You have to define one Titlebar element by yourself if you want to use figures for them.

Answered By: Jason Yang