I have run into several problems wanting to customize windows in Pysimplegui using use_custom_titlebar = True.
My system:
Problems:
alt+tabresizable = False does not seem to affect the behavior. It also doesn't work if
I set a fixed window size with the size argumentI appreciate in advance any contribution. Thank you
Example code:
import PySimpleGUI as sg
layout = [[sg.B('Exit', size = (12,3))]]
window = sg.Window('My window',
layout,
use_custom_titlebar = True,
size = (None, None),
resizable = False)
while True:
event, values = window.read()
if event in (None,'Exit'):
break
window.close()
use_custom_titlebar=True sets no_titlebar=True for your window. Under Windows, this sets window.TKroot.wm_overrideredirect(True), causing the (system) window manager to ignore the window. As one of the consequences, there is no taskbar icon.
Tcl/Tk documentation: wm overrideredirect
There are some tricks to deal with it when working directly with Tkinter (see, e.g., Making Tkinter windows show up in the taskbar) but we cannot do this directly via PySimpleGUI so far. Currently, I'm exploring how to make a dummy window to appear in the taskbar and to couple it with my window, but I don't have a working solution yet.
To keep my main window accessible even if it's behind another window, I'm using a system tray that always stays on top. (You may want to consider setting keep_on_top=True for your window, but sometimes it's simply not convenient.)
To prevent maximisation, you can either tweak the function Titlebar() in PySimpleGUI and comment out its part where the maximise-symbol is added like this:
return Column([[Column([icon_and_text_portion], pad=(0, 0), background_color=bc),
Column([[T(SYMBOL_TITLEBAR_MINIMIZE, text_color=tc, background_color=bc, enable_events=True, font=font, key=TITLEBAR_MINIMIZE_KEY),
# Text(SYMBOL_TITLEBAR_MAXIMIZE, text_color=tc, background_color=bc, enable_events=True, font=font,key=TITLEBAR_MAXIMIZE_KEY),
Text(SYMBOL_TITLEBAR_CLOSE, text_color=tc, background_color=bc, font=font, enable_events=True, key=TITLEBAR_CLOSE_KEY),
]],
element_justification='r', expand_x=True, grab=True, pad=(0, 0), background_color=bc)
]],
expand_x=True, grab=True, background_color=bc, pad=(0,0),metadata=TITLEBAR_METADATA_MARKER, key=key)
or you can remove the titlebar completely using no_titlebar=True in your window and add your own titlebar at the beginning of your layout, for example with this function (tweaked from https://github.com/PySimpleGUI/PySimpleGUI/blob/master/DemoPrograms/Demo_Window_Background_Image.py):
titlebar = [sg.Col([[sg.Text(your_titlebar_text, text_color=tc, background_color=bc, font=font, grab=True)]],
pad=(0, 0), background_color=bc),
sg.Col([[sg.Text(sg.SYMBOL_X, background_color=bc, enable_events=enable_events)]], # '❎'
element_justification='r', key='-X-', grab=True, pad=(0, 0), background_color=bc)]
(you may want to add sg.HorizontalSeparator() as an extra row in the titlebar).
As an example:
import PySimpleGUI as sg
titlebar = [[sg.Col([[sg.Text('My window', grab=True)]], pad=(0, 0)),
sg.Col([[sg.Text(sg.SYMBOL_X, enable_events=True, key='-X-')]], # '❎'
element_justification='r', grab=True, pad=(0, 0), expand_x=True)],
[sg.HorizontalSeparator()]]
layout = titlebar + [[sg.B('Exit', size=(12, 3))]]
window = sg.Window('My window', layout, no_titlebar=True, finalize=True)
while True:
event, values = window.read()
print(event)
if event in (None, 'Exit', '-X-'):
break
window.close()

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With