Intro. to Programming : Fall 2017 -Online

Csci 1020 September 17-23, 2017 Program Assignment 5

Write a GUI which displays 3 fonts on a canvas.

Here is the link to the sample code:

Note on the code

There are various options exercised in this sample. You may use different ones in your 3 font functions--a good idea to check them out--but your final code will not have all the extra stuff which this code has for illustration.

The canvas is given a width and height for the x and y axis dimensions, but y goes down instead of up as one may recall from usual math graphing practice. Below a canvas is created with differing x and y spans:

C = Canvas(W, width=400, height=300)

Take a piece of paper, draw your font, then figure out what kind of objects are needed (lines, rectangles, polygons, arcs, ...) to draw the font. Below, consider drawing a P, now find the (x,y) coordinate of points on the P, then use create_polygon to connect the dots.

Below is the source code of a program to create a Canvas and drw the P when the P button is pressed. Note that the Canvas background is black, and this is done by first drawing a black rectangle the size of the entire Canvas.

# canvas fun for P5 :
from Tkinter import *

W = Tk()

C = Canvas(W, width=400, height=300)


def draw_p():
    C.create_polygon( (250,100),(270,100),(290,120),(270,140),(250,140),



mainloop() # hang here forever, or until "Quit" button is pressed

Note that the order matters! The P is drawn on top of the black background. If things placed on the Canvas overlap, the last one is on top.

One can improve looks by little things. The image below has the width increased to 5.

def draw_p():
    C.create_polygon( (250,100),(270,100),(290,120),(270,140),(250,140),

Content is neither approved nor reviewed by FDLTCC.