sg_welcome.py

sg_welcome.py converts the Codeskulptor home page http://www.codeskulptor.org/ to tkinter, with some extensions.  Intro to the Canvas widget and the awkward way you write text to the canvas. Some items of note:

a)  I added an extra ‘Reset’ button which toggles between the two messages.  Lines 132, 133.

b) Note we have two types of widgets that we can place in the root window – a Frame, which you are familiar with from the first lessons, and a Canvas, which is new.  I suggest changing the row and column numbers as described in the comments starting at line 53 to see how you can shuffle a frame and a canvas around in the window.

c) Scott’s example changes a variable ‘message’ to change the display on the screen.  But writing text to the Canvas widget in tkinter is more complicated.  Instead you create a text object (examples on lines 71, 78 and 118) and then can either show it (default) or hide it (state = ‘hidden’).  So this works but it’s pretty awkward compared to just updating a variable.

You can see the mechanism inside either of the button event handlers.  Very dated technology, IMHO.  Also read the comment starting at line 87.

d) I used Helvetica as the font.  There are three font choices that are about as safe as tkinter can make them for cross-platform use -- Courier, Helvetica, and Times.  This is explained better in a comment starting at line 29.

e)  When the program opens you can slide the mouse over the “Message!” text and it turns green.  This is from the “activefill = ‘green’” option on line 118.  There was no reason to do this here  except to show how the option works, but it could be handy later on.

f) You can change the alignment of a create_text canvas text with ‘anchor’.  You can see an example by uncommenting lines 121 and 122.

OK, pretty basic stuff for the most part.  Key points to take away are that a Canvas is a widget type that allows you to do things like draw shapes or display graphics that you cannot do in a Frame.  And that manipulating text in a Canvas is awkward.