Skip to content

Commit 7ddf08b

Browse files
committed
Updated CustomTitlebar demo. New screenshots for docs
1 parent 9be24d6 commit 7ddf08b

5 files changed

Lines changed: 9 additions & 56 deletions

File tree

DemoPrograms/Demo_Titlebar_Custom_Dark_Theme.py

Lines changed: 9 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
11
import PySimpleGUI as sg
2-
32
"""
43
Demo showing how to remove the titlebar and replace with your own
54
Unlike previous demos that lacked a titlebar, this one provides a way for you
65
to "minimize" your window that does not have a titlebar. This is done by faking
76
the window using a hidden window that is minimized.
8-
9-
While this demo uses the button colors for the titlebar color, you can use anything you want.
10-
If possible it could be good to use combinations that are known to match like the input element colors
11-
or the button colors.
12-
13-
This code eventually grew into the internal implementation of the Titlebar element. It's a good example
14-
of how user code is just as powerful as internal PySimpleGUI code.
15-
16-
Copyright 2020 PySimpleGUI.org
7+
8+
The DarkGrey8 is already a theme in PySimpleGUI. It's here to show you how to add your own and have it them
9+
be used by your Custom Titlebar.
10+
11+
Copyright 2020, 2022 PySimpleGUI.org
1712
"""
1813

1914

@@ -32,55 +27,17 @@
3227

3328
sg.theme('DarkGrey8')
3429

35-
def dummy_minimized_window(title):
36-
"""
37-
Creates an invisible window that is minimized to the taskbar
38-
As soon as something happens to the window, it is closed and the function
39-
returns.
40-
The FocusIn event is set so that if the user restores the window from the taskbar, then the read
41-
wille return, the window will be closed, and the function will return
42-
"""
43-
44-
layout = [[sg.T('This is your window with a customized titlebar... you just cannot see it')]]
45-
window = sg.Window(title, layout, finalize=True, alpha_channel=0)
46-
window.minimize()
47-
window.bind('<FocusIn>', '-FOCUS-')
48-
window.read(close=True)
49-
50-
51-
def title_bar(title, text_color, background_color):
52-
"""
53-
Creates a Column element meant to be used as a single row. This row looks like a titlebar.
54-
:param title: The "title" to show in the titlebar
55-
:type title: str
56-
:return: A single Column element that can be used as a single row in your layout
57-
:type: sg.Column
58-
"""
59-
bc = background_color
60-
tc = text_color
61-
62-
return sg.Col([[sg.Col(
63-
[[sg.T(title,text_color=tc, background_color=bc, grab=True, expand_x=True)]],
64-
pad=(0, 0), background_color=bc, expand_x=True),
65-
sg.Col(
66-
[[sg.T('_', text_color=tc, background_color=bc, enable_events=True, key='-MINIMIZE-'),sg.Text('❎', text_color=tc, background_color=bc, enable_events=True, key='Exit')]],
67-
element_justification='r', key='-C-', pad=(0, 0), expand_x=True, background_color=bc, grab=True)]],
68-
pad=(0,0), grab=True, expand_x=True)
69-
70-
7130

7231

7332
def main():
7433
# sg.theme('light green 3')
7534
# sg.theme('dark red')
76-
sg.theme('DarkGrey8')
7735

7836
title = 'Customized Titlebar Window'
79-
# Here the titlebar colors are based on the theme. A few suggestions are shown. Try each of them
80-
layout = [ [title_bar(title, sg.theme_button_color()[0], sg.theme_button_color()[1])],
81-
# [title_bar(title, sg.theme_button_color()[1], sg.theme_slider_color())],
82-
# [title_bar(title, sg.theme_slider_color(), sg.theme_button_color()[0])],
83-
[sg.T('This is normal window text. The above is the fake "titlebar"')],
37+
38+
layout = [ [sg.Titlebar(title, sg.CUSTOM_TITLEBAR_ICON)],
39+
[sg.T('This is normal window text. The above is a "Custom Titlebar"')],
40+
[sg.T('They can be made by adding a Titlebar element to your layout')],
8441
[sg.T('Input something:')],
8542
[sg.Input(key='-IN-'), sg.Text(size=(12,1), key='-OUT-')],
8643
[sg.Button('Go')]]
@@ -92,10 +49,6 @@ def main():
9249
print(event, values)
9350
if event == sg.WIN_CLOSED or event == 'Exit':
9451
break
95-
if event == '-MINIMIZE-':
96-
window.hide()
97-
dummy_minimized_window(window.Title)
98-
window.un_hide()
9952
if event == 'Go':
10053
window['-OUT-'].update(values['-IN-'])
10154
window.close()
34.7 KB
Loading
36.8 KB
Loading
36.1 KB
Loading
34.7 KB
Loading

0 commit comments

Comments
 (0)