MCPcopy Index your code
hub / github.com/PySimpleGUI/PySimpleGUI / create_window

Function create_window

DemoPrograms/Demo_Desktop_Widget_Weather.py:193–244  ·  view source on GitHub ↗

Create the application window

(win_location, settings)

Source from the content-addressed store, hash-verified

191
192
193def create_window(win_location, settings):
194 """ Create the application window """
195 friends_name = settings.get('-friends name-', '')
196 col1 = sg.Column(
197 [[sg.Text(APP_DATA['City'], font=('Arial Rounded MT Bold', 18), background_color=BG_COLOR, text_color=TXT_COLOR, key='City'),
198 sg.Text(f' - {friends_name}' if friends_name else '', background_color=BG_COLOR, text_color=TXT_COLOR, font=('Arial Rounded MT Bold', 18),)],
199 [sg.Text(APP_DATA['Description'], font=('Arial', 12), pad=(10, 0), background_color=BG_COLOR, text_color=TXT_COLOR, key='Description')]],
200 background_color=BG_COLOR, key='COL1')
201
202 col2 = sg.Column([[sg.Image(data=APP_DATA['Icon'], size=(100, 100), background_color=BG_COLOR, key='Icon')]],
203 element_justification='center', background_color=BG_COLOR, key='COL2')
204
205 col3 = sg.Column([[sg.Text(APP_DATA['Updated'], font=('Arial', 8), background_color=BG_COLOR, text_color=TXT_COLOR, key='Updated')]],
206 pad=(10, 5), element_justification='left', background_color=BG_COLOR, key='COL3')
207
208 col4 = sg.Column(
209 [[sg.Text('Settings', font=('Arial', 8, 'italic'), background_color=BG_COLOR, text_color=TXT_COLOR, enable_events=True, key='-CHANGE-'),
210 sg.Text('Refresh', font=('Arial', 8, 'italic'), background_color=BG_COLOR, text_color=TXT_COLOR, enable_events=True, key='-REFRESH-')]],
211 pad=(10, 5), element_justification='right', background_color=BG_COLOR, key='COL4')
212
213 top_col = sg.Column([[col1, sg.Push(background_color=BG_COLOR), col2, sg.Text('×', font=('Arial Black', 16), pad=(0, 0), justification='right', background_color=BG_COLOR, text_color=TXT_COLOR, enable_events=True, key='-QUIT-')]], pad=(0, 0), background_color=BG_COLOR, key='TopCOL')
214
215 bot_col = sg.Column([[col3, col4]],
216 pad=(0, 0), background_color=BG_COLOR, key='BotCOL')
217
218 lf_col = sg.Column(
219 [[sg.Text(APP_DATA['Temp'], font=('Haettenschweiler', 90), pad=((10, 0), (0, 0)), justification='center', key='Temp')]],
220 pad=(10, 0), element_justification='center', key='LfCOL')
221
222 rt_col = sg.Column([metric_row('Feels Like'), metric_row('Wind'), metric_row('Humidity'), metric_row('Precip 1hr'), metric_row('Pressure')],
223 pad=((15, 0), (25, 5)), key='RtCOL')
224
225 layout = [[top_col],
226 [lf_col, rt_col],
227 [bot_col],
228 [sg.Text(f'PSG: {sg.ver} Tk:{sg.framework_version} Py:{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}', font=('Arial', 8), justification='c', background_color=BG_COLOR, text_color=TXT_COLOR, pad=(0,0), expand_x=True)]]
229
230 window = sg.Window(layout=layout, title='Weather Widget', margins=(0, 0), finalize=True, location=win_location,
231 element_justification='center', keep_on_top=True, no_titlebar=True, grab_anywhere=True, alpha_channel=ALPHA,
232 right_click_menu=[[''], ['Edit Me', 'Versions', 'Exit',]], enable_close_attempted_event=True)
233
234 for col in ['COL1', 'COL2', 'TopCOL', 'BotCOL', '-QUIT-']:
235 window[col].expand(expand_y=True, expand_x=True)
236
237 for col in ['COL3', 'COL4', 'LfCOL', 'RtCOL']:
238 window[col].expand(expand_x=True)
239
240 window['-CHANGE-'].set_cursor('hand2')
241 window['-QUIT-'].set_cursor('hand2')
242 window['-REFRESH-'].set_cursor('hand2')
243
244 return window
245
246
247def update_metrics(window):

Callers 1

mainFunction · 0.70

Calls 4

metric_rowFunction · 0.85
expandMethod · 0.80
getMethod · 0.45
set_cursorMethod · 0.45

Tested by

no test coverage detected