PySimpleGUI/DemoPrograms/Demo_Titlebar_Custom_Dark_T...

88 lines
3.2 KiB
Python
Raw Normal View History

import PySimpleGUI as sg
"""
Demo showing how to remove the titlebar and replace with your own
2020-08-12 15:02:17 +00:00
Unlike previous demos that lacked a titlebar, this one provides a way for you
to "minimize" your window that does not have a titlebar. This is done by faking
the window using a hidden window that is minimized.
Copyright 2020 PySimpleGUI.org
"""
# If not running 4.28.0.4+ that has the DarkGrey8 theme, then uncomment to get it added.
# DarkGrey8 = {'BACKGROUND': '#19232D',
# 'TEXT': '#ffffff',
# 'INPUT': '#32414B',
# 'TEXT_INPUT': '#ffffff',
# 'SCROLL': '#505F69',
# 'BUTTON': ('#ffffff', '#32414B'),
# 'PROGRESS': ('#505F69', '#32414B'),
# 'BORDER': 1, 'SLIDER_DEPTH': 0, 'PROGRESS_DEPTH': 0,
# }
#
# sg.theme_add_new('DarkGrey8', DarkGrey8)
2020-08-12 14:28:03 +00:00
2020-08-12 14:58:09 +00:00
def dummy_minimized_window(title):
2020-08-12 14:28:03 +00:00
"""
Creates an invisible window that is minimized to the taskbar
As soon as something happens to the window, it is closed and the function
returns.
The FocusIn event is set so that if the user restores the window from the taskbar, then the read
wille return, the window will be closed, and the function will return
"""
2020-08-12 15:02:17 +00:00
2020-08-12 14:58:09 +00:00
layout = [[sg.T('This is your window with a customized titlebar... you just cannot see it')]]
window = sg.Window(title, layout, finalize=True, alpha_channel=0)
2020-08-12 14:28:03 +00:00
window.minimize()
window.bind('<FocusIn>', '-FOCUS-')
window.read(close=True)
def title_bar(title):
2020-08-12 14:58:09 +00:00
"""
Creates a "row" that can be added to a layout. This row looks like a titlebar
:param title: The "title" to show in the titlebar
:type title: str
2020-08-12 15:02:17 +00:00
:return: A list of elements (i.e. a "row" for a layout)
:type: List[sg.Element]
2020-08-12 14:58:09 +00:00
"""
bg = sg.theme_input_background_color()
return [sg.Col([[sg.T(title, background_color=bg )]], pad=(0, 0), background_color=bg),
2020-08-12 14:28:03 +00:00
sg.Col([[sg.T('_', background_color=bg, enable_events=True, key='-MINIMIZE-'),sg.Text('', background_color=bg, enable_events=True, key='Exit')]], element_justification='r', k='-C-', pad=(0, 0), background_color=bg)]
def main():
2020-08-12 14:28:03 +00:00
sg.theme('DarkGrey8')
2020-08-12 14:58:09 +00:00
title = 'Customized Titlebar Window'
layout = [ title_bar(title),
[sg.T('This is normal window text. The above is the fake "titlebar"')],
[sg.T('Input something:')],
[sg.Input(key='-IN-'), sg.Text(size=(12,1), key='-OUT-')],
[sg.Button('Go')] ]
2020-08-12 14:58:09 +00:00
window = sg.Window(title, layout, resizable=True, no_titlebar=True, grab_anywhere=True, keep_on_top=True, margins=(0,0), finalize=True)
2020-08-12 15:02:17 +00:00
window['-C-'].expand(True, False, False) # expand the titlebar's rightmost column so that it resizes correctly
while True: # Event Loop
event, values = window.read()
print(event, values)
if event == sg.WIN_CLOSED or event == 'Exit':
break
2020-08-12 14:28:03 +00:00
if event == '-MINIMIZE-':
window.hide()
2020-08-12 14:58:09 +00:00
dummy_minimized_window(window.Title)
2020-08-12 14:28:03 +00:00
window.un_hide()
if event == 'Go':
window['-OUT-'].update(values['-IN-'])
window.close()
2020-08-12 15:02:17 +00:00
if __name__ == '__main__':
main()