-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy_tkinter_settings.py
46 lines (38 loc) · 1.18 KB
/
my_tkinter_settings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
"""
Functions for easily setting up Tkinter window settings
Author: Marco P. L. Ribeiro
Date: June 2019
MIT License
Copyright (c) 2019 Marco P. L. Ribeiro
"""
def configure_window(master, title="Python Application", width=600, height=600, resizable=True, centred=True, bg=None):
'''Configure Tkinter GUI window
Parameters
----------
master : Tk object
title : str
Application title
width : int
Application width
height : int
Application height
resizable : bool
Allow resizing of application
centred : bool
Centre application on screen
bg : tkinter color string
Application background colour
'''
master.title(title)
if centred:
s_width = master.winfo_screenwidth()
s_height = master.winfo_screenheight()
x = (s_width - width)//2
y = (s_height - height)//2
master.geometry('%dx%d+%d+%d' % (width, height, x, y))
else:
master.geometry('{}x{}'.format(width, height))
if not resizable:
master.resizable(width=False, height=False)
if bg is not None:
master.configure(bg=bg)