Only tested on VSCode *
- Install the CMU Graphics library from their website: CMU Graphics Download.
- Move the folder titled
cmu_graphcisinto the directory with your python file that imports it.- Don't forget to add it to your .gitignore!
- Add
from cmu_graphics import *to the top of the python file. - At the bottom of your file, add a function called
runApp()with the keyword argumentswidthandheight. These will define the width and height of your window. - All of your code that will be drawn must be inside of a function called
redrawAll(). It takes a single argument,app.
Notes:
- All shape functions (
Rect,Polygon, etc.) are replaced withdrawRect,drawPolygon, etc. - If your project throws an error that ends with a message about a module named 'pygame', initialize and activiate a
.venvand runpip install pygamein the command line.
This is an example of what your file should look like:
from cmu_graphics import *
def redrawAll(app):
exampleShape: Rect = drawRect(
100,100,
100,100,
fill=gradient("white","black", start="right")
)
exampleLabel: Label = drawLabel(
'Jello, World!',
120,350,
size=41,
fill='cornflowerBlue',
font='arial'
)
app.title = "My Super Awesome Example Program"
runApp(
width=400,
height=400
)This is what your file structure should look like:
| DIRECTORY_NAME
\| cmu_graphics
| main.py