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.

• Create a function for 3 fonts, your choice, each function drawing a font (letter or number) on the canvas.
• Your GUI should have 4 buttons: the Quit button, and a button for each of your three fonts.
• As usual, you may enhance the GUI as you wish. Some padding around widgets (buttons, labels, i.e. everything placed on the window W using the .grid placement method) might make things look better. An image somewhere could be attractive. You might play some uplifting tune right after the GUI is opened. Adding directions somewhere above or below the buttons and other items is a nice touch.
• Email your program with all necessary files attached ( the .py program file, images, whatever) to me: ted@fdltcc.edu

I can't check it out without these files. Snapshot images of the code and running program are a nice extra, and thanks, but I MUST have the source code and necessary files in order to run the program.
• Enter a remark in the D2L discussion under p5.

Here is the link to the sample code:

### Note on the sample.py 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 sample.py 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 : p.py
from Tkinter import *

W = Tk()

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

B=Button(W,text="Quit",command=quit)
B.pack()

def draw_p():
C.create_polygon( (250,100),(270,100),(290,120),(270,140),(250,140),
(250,180),outline="green")

Pbutton=Button(W,text="P",command=draw_p)
Pbutton.pack()

C.create_rectangle(0,0,400,300,fill="black")

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),
(250,180),outline="green",width=5)


Content is neither approved nor reviewed by FDLTCC.