Skip to content

Commit da4d739

Browse files
committed
Added docstrings to the Window class.
1 parent 5fc5860 commit da4d739

File tree

1 file changed

+46
-8
lines changed

1 file changed

+46
-8
lines changed

src/aturtle/window.py

+46-8
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,21 @@
1111

1212
class Window:
1313

14+
"""
15+
A Window holding a canvas.
16+
"""
17+
1418
_windows = []
1519

1620
def __init__(self, width=320, height=320, x=None, y=None,
1721
fill_color='white', title='A-Turtle'):
22+
"""
23+
Initialize a Window with the given `width` and `height`, filled in
24+
`fill_color`, with the given `title`.
25+
26+
Positive `x` and `y` values place the Window's from the screen's top-
27+
left corner. Negative values place it from the bottom-right corner.
28+
"""
1829

1930
tk_window = tkinter.Tk() if not Window._windows else tkinter.Toplevel()
2031
Window._windows.append(self)
@@ -63,13 +74,18 @@ def __init__(self, width=320, height=320, x=None, y=None,
6374

6475
@property
6576
def x(self):
66-
77+
"""
78+
The Window's horizontal position.
79+
"""
6780
return self._tk_window.winfo_x()
6881

6982

7083
@x.setter
7184
def x(self, value):
72-
85+
"""
86+
Set the Window's horizontal position.
87+
Negative values place the Window from the right of the screen.
88+
"""
7389
if value < 0:
7490
value = self._tk_window.winfo_screenwidth() - self.width + value
7591

@@ -78,13 +94,18 @@ def x(self, value):
7894

7995
@property
8096
def y(self):
81-
97+
"""
98+
The Window's vertical position.
99+
"""
82100
return self._tk_window.winfo_y()
83101

84102

85103
@y.setter
86104
def y(self, value):
87-
105+
"""
106+
Set the Window's vertical position.
107+
Negative values place the Window from the bottom of the screen.
108+
"""
88109
if value < 0:
89110
value = self._tk_window.winfo_screenheight() - self.height + value
90111

@@ -93,25 +114,33 @@ def y(self, value):
93114

94115
@property
95116
def width(self):
96-
117+
"""
118+
The Window width.
119+
"""
97120
return self._tk_window.winfo_width()
98121

99122

100123
@width.setter
101124
def width(self, value):
102-
125+
"""
126+
Set the Window width.
127+
"""
103128
self._tk_window.geometry(f'{value}x{self.height}')
104129

105130

106131
@property
107132
def height(self):
108-
133+
"""
134+
The Window height.
135+
"""
109136
return self._tk_window.winfo_height()
110137

111138

112139
@height.setter
113140
def height(self, value):
114-
141+
"""
142+
Set the Window height.
143+
"""
115144
self._tk_window.geometry(f'{self.width}x{value}')
116145

117146

@@ -237,7 +266,12 @@ def unbind_direct_key(self, keysym=None):
237266

238267

239268
def close(self):
269+
"""
270+
Closes this Window.
240271
272+
Raises RuntimeError if this is the first created Window and there still
273+
are other open Windows.
274+
"""
241275
is_root = self._tk_window is Window._windows[0]._tk_window
242276
if is_root and len(Window._windows) > 1:
243277
raise RuntimeError('Must be last to close.')
@@ -251,7 +285,11 @@ def close(self):
251285

252286
@classmethod
253287
def close_all(cls, strict=True):
288+
"""
289+
Closes all Windows.
254290
291+
Raises RuntimeError if `strict` is true and there are no open Windows.
292+
"""
255293
if not cls._windows:
256294
if strict:
257295
raise RuntimeError('No windows.')

0 commit comments

Comments
 (0)