-
Notifications
You must be signed in to change notification settings - Fork 0
/
TkExtra.py
58 lines (49 loc) · 1.68 KB
/
TkExtra.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
47
48
49
50
51
52
53
54
55
56
57
58
import tkinter as tk
def _agsmerge(args):
"""Internal functions.\n
Merges lists/tuples."""
a = []
if isinstance(args, (tuple, list)):
for i in args:
if isinstance(i, (tuple, list)):
a.extend(i)
else:
a.append(i)
return a or args
# Define Grid layout
def grid(root, row, column):
"Defines rows and columns if grid method is used"
for y in range(column):
tk.Grid.columnconfigure(root, y, weight=1)
for x in range(row):
tk.Grid.rowconfigure(root, x, weight=1)
class Canvas(tk.Canvas):
def create_roundsqaure(self, ags=(), *args, **kw):
'Internal function.'
x, y, w, h, c = _agsmerge((ags, args))
ids = []
cnf = dict(**kw)
for i in ('extent', 'start', 'style'):
cnf.pop(i, None)
for i in ('joinstyle', 'smooth', 'slinesteps'):
kw.pop(i, None)
points = ( # Arc points:-
(x, y, x+2*c, y+2*c),
(x, y+h-2*c, x+2*c, y+h),
(x+w-2*c, y+h-2*c, x+w, y+h),
(x+w-2*c, y, x+w, y+2*c),
# Polygon points:-
(x+c, y, x+w-c, y),
(x+c, y+h, x+w-c, y+h),
(x, y+c, x, y+h-c),
(x+w, y+c, x+w, y+h-c))
for i in range(len(points)):
if i <= 3:
kw['start'] = 90*(i+1)
ids.append(self._create('arc', points[i], kw.copy()))
else:
ids.append(self._create('polygon', points[i], cnf.copy()))
return tuple(ids)
# Circle for the canvas
def create_circle(self, x, y, r, **kwargs):
return self.create_oval(x-r, y-r, x+r, y+r, **kwargs)