simplegraphics-python 1.0.12__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- simplegraphics-python-1.0.12/PKG-INFO +396 -0
- simplegraphics-python-1.0.12/README.md +381 -0
- simplegraphics-python-1.0.12/SimpleGraphics/__init__.py +1 -0
- simplegraphics-python-1.0.12/SimpleGraphics/__main__.py +1330 -0
- simplegraphics-python-1.0.12/setup.cfg +4 -0
- simplegraphics-python-1.0.12/setup.py +22 -0
- simplegraphics-python-1.0.12/simplegraphics_python.egg-info/PKG-INFO +396 -0
- simplegraphics-python-1.0.12/simplegraphics_python.egg-info/SOURCES.txt +8 -0
- simplegraphics-python-1.0.12/simplegraphics_python.egg-info/dependency_links.txt +1 -0
- simplegraphics-python-1.0.12/simplegraphics_python.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: simplegraphics-python
|
|
3
|
+
Version: 1.0.12
|
|
4
|
+
Summary: A simple graphics wrapper on top of tkinter
|
|
5
|
+
Home-page: https://cspages.ucalgary.ca/~bdstephe/217_P24/
|
|
6
|
+
Author: Ben Stephenson
|
|
7
|
+
Author-email: ben.stephenson@ucalgary.ca
|
|
8
|
+
Maintainer: Grygoriy Gromko
|
|
9
|
+
Maintainer-email: gr.gromko@gmail.com
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Requires-Python: >=3.1.0
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
|
|
16
|
+
****SimpleGraphics**** is a lightweight Python graphics library designed as a convenient wrapper around the standard ****tkinter**** library. Its primary purpose is to make graphical programming accessible even to beginners: simply import the module, and a graphics window opens automatically, without the need to create classes, objects or manually call mainloop.
|
|
17
|
+
|
|
18
|
+
Unlike tkinter, where developers need to work with controls and other window components, events and geometry managers, SimpleGraphics allows you to focus on drawing, user interaction and animation.
|
|
19
|
+
|
|
20
|
+
The library was created by ****Ben Stephenson****, a professor at the University of Calgary (Canada). It was developed for educational purposes and is actively used in introductory computer science courses.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
## Basic Drawing Functions
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### line(...)
|
|
27
|
+
|
|
28
|
+
****Purpose:**** Draws a line (or polyline) connecting multiple points (x1, y1, x2, y2, ...).
|
|
29
|
+
|
|
30
|
+
****Example:****
|
|
31
|
+
|
|
32
|
+
line(10, 10, 100, 100)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
### curve(...)
|
|
36
|
+
|
|
37
|
+
****Purpose:**** Draws a smooth curve passing through given points.
|
|
38
|
+
|
|
39
|
+
****Example:****
|
|
40
|
+
|
|
41
|
+
curve(10, 10, 60, 30, 100, 10)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
### blob(...)
|
|
45
|
+
|
|
46
|
+
****Purpose:**** Draws a closed smooth curve (spline), similar to a freeform shape.
|
|
47
|
+
|
|
48
|
+
****Example:****
|
|
49
|
+
|
|
50
|
+
blob(50, 100, 100, 150, 150, 100, 100, 50)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
### rect(x, y, w, h)
|
|
54
|
+
|
|
55
|
+
****Purpose:**** Draws a rectangle with top-left corner at (x, y) and specified width and height.
|
|
56
|
+
|
|
57
|
+
****Example:****
|
|
58
|
+
|
|
59
|
+
rect(50, 50, 100, 60)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
### ellipse(x, y, w, h)
|
|
63
|
+
|
|
64
|
+
****Purpose:**** Draws an ellipse inscribed in a rectangle with coordinates (x, y) and dimensions w, h.
|
|
65
|
+
|
|
66
|
+
****Example:****
|
|
67
|
+
|
|
68
|
+
ellipse(30, 30, 120, 80)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
### circle(x, y, d)
|
|
72
|
+
|
|
73
|
+
****Purpose:**** Draws a circle with center at (x, y) and diameter d.
|
|
74
|
+
|
|
75
|
+
****Example:****
|
|
76
|
+
|
|
77
|
+
circle(100, 100, 50)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
### arc(x, y, w, h, start, extent)
|
|
81
|
+
|
|
82
|
+
****Purpose:**** Draws an elliptical arc starting at angle start (in degrees) spanning extent degrees.
|
|
83
|
+
|
|
84
|
+
****Example:****
|
|
85
|
+
|
|
86
|
+
arc(60, 60, 100, 100, 0, 90)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
### pieSlice(x, y, w, h, start, extent)
|
|
90
|
+
|
|
91
|
+
****Purpose:**** Draws a pie slice (like a pizza slice) based on an arc.
|
|
92
|
+
|
|
93
|
+
****Example:****
|
|
94
|
+
|
|
95
|
+
pieSlice(50, 50, 100, 100, 0, 45)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
### polygon(...)
|
|
99
|
+
|
|
100
|
+
****Purpose:**** Draws a filled polygon through a list of points.
|
|
101
|
+
|
|
102
|
+
****Example:****
|
|
103
|
+
|
|
104
|
+
polygon(10, 10, 100, 50, 50, 100)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
### text(x, y, what, align="c", ang=0)
|
|
108
|
+
|
|
109
|
+
****Purpose:**** Displays text at point (x, y). Alignment (align) and rotation angle (ang) can be modified.
|
|
110
|
+
|
|
111
|
+
****Example:****
|
|
112
|
+
|
|
113
|
+
text(200, 150, "Hello, world!", align="c", ang=0)
|
|
114
|
+
|
|
115
|
+
## Color and Font
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
### setColor(r, g=None, b=None)
|
|
119
|
+
|
|
120
|
+
****Purpose:**** Sets both fill and outline colors simultaneously.
|
|
121
|
+
|
|
122
|
+
****Example:****
|
|
123
|
+
|
|
124
|
+
setColor("blue")
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
### setFill(...), setOutline(...)
|
|
128
|
+
|
|
129
|
+
****Purpose:**** Sets fill or outline colors separately.
|
|
130
|
+
|
|
131
|
+
****Example:****
|
|
132
|
+
|
|
133
|
+
setFill("yellow")
|
|
134
|
+
|
|
135
|
+
setOutline(255, 0, 0)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
### setWidth(w)
|
|
139
|
+
|
|
140
|
+
****Purpose:**** Sets line thickness in pixels.
|
|
141
|
+
|
|
142
|
+
****Example:****
|
|
143
|
+
|
|
144
|
+
setWidth(4)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
### setFont(family, size, modifiers)
|
|
148
|
+
|
|
149
|
+
****Purpose:**** Sets text font. Modifiers like "bold", "italic", "underline" can be added.
|
|
150
|
+
|
|
151
|
+
****Example:****
|
|
152
|
+
|
|
153
|
+
setFont("Arial", 14, "bold italic")
|
|
154
|
+
|
|
155
|
+
## Window Management
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
### resize(w, h)
|
|
159
|
+
|
|
160
|
+
****Purpose:**** Changes the graphics window size.
|
|
161
|
+
|
|
162
|
+
****Example:****
|
|
163
|
+
|
|
164
|
+
resize(1024, 768)
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
### background(color)
|
|
168
|
+
|
|
169
|
+
****Purpose:**** Sets window background color.
|
|
170
|
+
|
|
171
|
+
****Example:****
|
|
172
|
+
|
|
173
|
+
background("lightgray")
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
### getWidth(), getHeight()
|
|
177
|
+
|
|
178
|
+
****Purpose:**** Returns window dimensions in pixels.
|
|
179
|
+
|
|
180
|
+
****Example:****
|
|
181
|
+
|
|
182
|
+
w, h = getWidth(), getHeight()
|
|
183
|
+
|
|
184
|
+
## Keyboard Interaction
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
### getTyped()
|
|
188
|
+
|
|
189
|
+
****Purpose:**** Returns user input text and clears the buffer.
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
### peekTyped()
|
|
193
|
+
|
|
194
|
+
****Purpose:**** Returns text without clearing the buffer.
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
### getKeys(), peekKeys(), getHeldKeys()
|
|
198
|
+
|
|
199
|
+
****Purpose:**** Works with pressed keys (single press or held keys).
|
|
200
|
+
|
|
201
|
+
## Mouse Interaction
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
### mousePos(), mouseX(), mouseY()
|
|
205
|
+
|
|
206
|
+
****Purpose:**** Returns mouse cursor coordinates.
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
### leftButtonPressed(), middleButtonPressed(), rightButtonPressed()
|
|
210
|
+
|
|
211
|
+
****Purpose:**** Checks if corresponding mouse button is pressed.
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
### getMouseEvent(), peekMouseEvent(), clearMouseEvents()
|
|
215
|
+
|
|
216
|
+
****Purpose:**** Works with mouse event queue (presses, releases).
|
|
217
|
+
|
|
218
|
+
## Animation
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
### doAnimate(func)
|
|
222
|
+
|
|
223
|
+
****Purpose:**** Starts continuous execution of a function for animation.
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
### noAnimate()
|
|
227
|
+
|
|
228
|
+
****Purpose:**** Stops animation.
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
### animationTime(ms)
|
|
232
|
+
|
|
233
|
+
****Purpose:**** Sets or returns frame interval in milliseconds (default is 50).
|
|
234
|
+
|
|
235
|
+
****Example:****
|
|
236
|
+
|
|
237
|
+
from SimpleGraphics import \*
|
|
238
|
+
|
|
239
|
+
shape = circle(0, 0, 50)
|
|
240
|
+
|
|
241
|
+
def animate():
|
|
242
|
+
|
|
243
|
+
move(shape, mouseX(), mouseY())
|
|
244
|
+
|
|
245
|
+
doAnimate(animate)
|
|
246
|
+
|
|
247
|
+
## Object Manipulation
|
|
248
|
+
|
|
249
|
+
|
|
250
|
+
### move(obj, x, y)
|
|
251
|
+
|
|
252
|
+
****Purpose:**** Moves object to new position.
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
### delete(obj), clear()
|
|
256
|
+
|
|
257
|
+
****Purpose:**** Deletes object or all objects.
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
### scale(obj, xs, ys), putUp(obj), putDown(obj)
|
|
261
|
+
|
|
262
|
+
****Purpose:**** Scales object, changes display order.
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
### checkCollision(obj1, obj2)
|
|
266
|
+
|
|
267
|
+
****Purpose:**** Returns True if two objects intersect.
|
|
268
|
+
|
|
269
|
+
## Image Handling
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
### createImage(w, h), loadImage(fname)
|
|
273
|
+
|
|
274
|
+
****Purpose:**** Creates or loads an image.
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
### putPixel(img, x, y, r, g, b), getPixel(img, x, y)
|
|
278
|
+
|
|
279
|
+
****Purpose:**** Works with image pixels.
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
### drawImage(img, x, y)
|
|
283
|
+
|
|
284
|
+
****Purpose:**** Draws image on window.
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
### savePPM(img, fname), saveGIF(img, fname), saveEPS(fname)
|
|
288
|
+
|
|
289
|
+
****Purpose:**** Saves images or entire window to file.
|
|
290
|
+
|
|
291
|
+
## Termination
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
### update()
|
|
295
|
+
|
|
296
|
+
****Purpose:**** Forces window content update.
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
### close(), closed()
|
|
300
|
+
|
|
301
|
+
****Purpose:**** Closes or checks window status.
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
### version()
|
|
305
|
+
|
|
306
|
+
****Purpose:**** Returns library version
|
|
307
|
+
|
|
308
|
+
## Sample Program
|
|
309
|
+
|
|
310
|
+
from SimpleGraphics import \*
|
|
311
|
+
|
|
312
|
+
setColor("red")
|
|
313
|
+
|
|
314
|
+
circle(200, 150, 100)
|
|
315
|
+
|
|
316
|
+
setFill("yellow")
|
|
317
|
+
|
|
318
|
+
rect(150, 250, 100, 60)
|
|
319
|
+
|
|
320
|
+
text(200, 340, "SimpleGraphics!")
|
|
321
|
+
|
|
322
|
+
|
|
323
|
+
Known Bugs:
|
|
324
|
+
* It appears that different operating systems number the buttons
|
|
325
|
+
differently. While button 1 always seems to be the left button,
|
|
326
|
+
whether button 2 is the right button or the middle button seems to vary.
|
|
327
|
+
|
|
328
|
+
* Changing to a new font using setFont and then displaying text can
|
|
329
|
+
result in previously drawn text being updated to use the new font.
|
|
330
|
+
The exact circumstances that cause this to occur are currently unclear.
|
|
331
|
+
|
|
332
|
+
* Resize seems to fail on occasion. The program that displays
|
|
333
|
+
all of the colors has demonstrated this behaviour occasionally.
|
|
334
|
+
|
|
335
|
+
* No event is captured when the user resizes the window with the mouse.
|
|
336
|
+
The canvas should be resized to match the window so that getWidth() and
|
|
337
|
+
getHeight() can be used to help scale a drawing to fit the window.
|
|
338
|
+
|
|
339
|
+
* Resize doesn't seem to be actually resizing the window on some versions
|
|
340
|
+
of Cygwin -- It just resizes the canvas and the window fails to resize
|
|
341
|
+
with it. Could this be related to the resize bug noted previously?
|
|
342
|
+
|
|
343
|
+
Please report bugs by sending email to ben.stephenson@ucalgary.ca.
|
|
344
|
+
|
|
345
|
+
Revision History:
|
|
346
|
+
v1.0.0 -- Publicly released January 23, 2014
|
|
347
|
+
v1.0.1 -- Publicly released February 7, 2014
|
|
348
|
+
Added close function to allow the programmer to close the window
|
|
349
|
+
Added the setWindowTitle function to allow the programmer
|
|
350
|
+
to change the contents of the window's title bar
|
|
351
|
+
SimpleGraphics now maintains a list of image references
|
|
352
|
+
so that images don't disappear when the function ends
|
|
353
|
+
setWidth() now impacts polygons, blobs, arcs and pie slices
|
|
354
|
+
v1.0.2 -- Publicly released February 16, 2014
|
|
355
|
+
Fixed a bug in the close function where it could attempt
|
|
356
|
+
to invoke a method on a None object without successfully
|
|
357
|
+
catching the exception.
|
|
358
|
+
v1.0.3 -- Publicly released August 19, 2014
|
|
359
|
+
Added savePPM and saveGIF functions for images
|
|
360
|
+
v1.0.4 -- Publicly released September 26, 2014
|
|
361
|
+
Added a try/except around the import for unregister so a
|
|
362
|
+
better error message is displayed when SimpleGraphics.py is
|
|
363
|
+
run with Python 2.x.y
|
|
364
|
+
v1.0.5 -- Publicly released November 4, 2014
|
|
365
|
+
Adjusted the implementation of getPixel to adapt to
|
|
366
|
+
PhotoImage.get() returning a string in most versions, but a
|
|
367
|
+
tuple in Python 3.4.x for Windows.
|
|
368
|
+
v1.0.6 -- Publicly released September 4, 2015
|
|
369
|
+
Fixed several bugs related to drawing rectangles with widths
|
|
370
|
+
and/or heights of 1.
|
|
371
|
+
Added a name to each font and improved the handling of font
|
|
372
|
+
modifiers. This may have fixed the problem with setFont.
|
|
373
|
+
Added the fontList and setJoinStyle functions
|
|
374
|
+
Added the keys set and the functions for accessing it (getKeys,
|
|
375
|
+
getHeldKeys and peekKeys)
|
|
376
|
+
v1.0.7 -- Publicly released October 21, 2015
|
|
377
|
+
In Python 3.5.0 the % operator will not accept a floating
|
|
378
|
+
point value for a hexadecimal format. Several int() casts
|
|
379
|
+
were added to work around this problem.
|
|
380
|
+
v1.0.8 -- Publicly released March 17, 2017
|
|
381
|
+
Added setArrow so that lines and curves can include arrow heads
|
|
382
|
+
Added setArrowShape so that the shape of the arrowhead can be
|
|
383
|
+
controlled
|
|
384
|
+
v1.0.9 -- Publicly released October 3, 2017
|
|
385
|
+
Added exception checks to background and drawImage to avoid
|
|
386
|
+
crashes at shutdown when __canvas gets set to None before
|
|
387
|
+
the last drawing operations are attempted.
|
|
388
|
+
v1.0.10 -- Publicly released June 28, 2019
|
|
389
|
+
Fixed a bug where 1x1 rectangles were not being drawn
|
|
390
|
+
Fixed a bug where lists passed to the line function were being
|
|
391
|
+
modified when they shouldn't be
|
|
392
|
+
v1.0.11 -- Publicly released April 28, 2024
|
|
393
|
+
Fixed a bug where rectangles with width 1 xor height 1 were
|
|
394
|
+
being drawn 1 pixel too narrow / 1 pixel too short
|
|
395
|
+
Added the optional angle argument parameter to text when
|
|
396
|
+
the Python version is greater than or equal to X.Y.Z.
|