11
11
12
12
class Window :
13
13
14
+ """
15
+ A Window holding a canvas.
16
+ """
17
+
14
18
_windows = []
15
19
16
20
def __init__ (self , width = 320 , height = 320 , x = None , y = None ,
17
21
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
+ """
18
29
19
30
tk_window = tkinter .Tk () if not Window ._windows else tkinter .Toplevel ()
20
31
Window ._windows .append (self )
@@ -63,13 +74,18 @@ def __init__(self, width=320, height=320, x=None, y=None,
63
74
64
75
@property
65
76
def x (self ):
66
-
77
+ """
78
+ The Window's horizontal position.
79
+ """
67
80
return self ._tk_window .winfo_x ()
68
81
69
82
70
83
@x .setter
71
84
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
+ """
73
89
if value < 0 :
74
90
value = self ._tk_window .winfo_screenwidth () - self .width + value
75
91
@@ -78,13 +94,18 @@ def x(self, value):
78
94
79
95
@property
80
96
def y (self ):
81
-
97
+ """
98
+ The Window's vertical position.
99
+ """
82
100
return self ._tk_window .winfo_y ()
83
101
84
102
85
103
@y .setter
86
104
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
+ """
88
109
if value < 0 :
89
110
value = self ._tk_window .winfo_screenheight () - self .height + value
90
111
@@ -93,25 +114,33 @@ def y(self, value):
93
114
94
115
@property
95
116
def width (self ):
96
-
117
+ """
118
+ The Window width.
119
+ """
97
120
return self ._tk_window .winfo_width ()
98
121
99
122
100
123
@width .setter
101
124
def width (self , value ):
102
-
125
+ """
126
+ Set the Window width.
127
+ """
103
128
self ._tk_window .geometry (f'{ value } x{ self .height } ' )
104
129
105
130
106
131
@property
107
132
def height (self ):
108
-
133
+ """
134
+ The Window height.
135
+ """
109
136
return self ._tk_window .winfo_height ()
110
137
111
138
112
139
@height .setter
113
140
def height (self , value ):
114
-
141
+ """
142
+ Set the Window height.
143
+ """
115
144
self ._tk_window .geometry (f'{ self .width } x{ value } ' )
116
145
117
146
@@ -237,7 +266,12 @@ def unbind_direct_key(self, keysym=None):
237
266
238
267
239
268
def close (self ):
269
+ """
270
+ Closes this Window.
240
271
272
+ Raises RuntimeError if this is the first created Window and there still
273
+ are other open Windows.
274
+ """
241
275
is_root = self ._tk_window is Window ._windows [0 ]._tk_window
242
276
if is_root and len (Window ._windows ) > 1 :
243
277
raise RuntimeError ('Must be last to close.' )
@@ -251,7 +285,11 @@ def close(self):
251
285
252
286
@classmethod
253
287
def close_all (cls , strict = True ):
288
+ """
289
+ Closes all Windows.
254
290
291
+ Raises RuntimeError if `strict` is true and there are no open Windows.
292
+ """
255
293
if not cls ._windows :
256
294
if strict :
257
295
raise RuntimeError ('No windows.' )
0 commit comments