z_flag_norway_sudan.py

z_flag_norway_sudan.py    This one should run in V3 or V2 without editing ‘tkinter’.  Check out how I did it in lines 14-17.

OK, let’s slap some shapes on a couple of canvases for practice.  You can view the flag of Norway here:  https://www.cia.gov/library/publications/the-world-factbook/flags/flagtemplate_no.html   And here’s Sudan’s flag:  https://www.cia.gov/library/publications/the-world-factbook/flags/flagtemplate_su.html. The rigorous way to do this would be to do a screen capture and then measure the dimensions in an imaging editor like Photoshop.  For these I just eye-balled it, assigning a 3:2 aspect ratio to the Norwegian flag and 2:1 to Sudan’s.  I just checked them and Norway should be 475/285 or 3.33/2, but Sudan measures 476/238 or 2:1, so I got that one right. So Norway first: for the shapes I just drew 2 horizontal and two vertical lines with .create_line on top of a red background and adjusted the line widths, lines 49-53.  It’s easier to draw a line than a rectangle.  The overall shapes are not quite right because the aspect ratio is off but you can fix that.

For the colors I started with the defaults “red”, “white” and “blue”.  “White” is OK, “red” is a bit too bright compared to the target and “blue” is too blue.  I left ‘red’ for you to modify. For the blue color, I first checked the web-safe colors (the 216 colors that both Microsoft and Windows supported back in the 8 bit color days) and picked what I thought was a good match.  I assigned this to the variable “Norway_blue” at line 46 and substituted it for the horizontal line.  I left the vertical line for you to change.  This color is not quite dark enough so you’d need to tweak the RGB values a bit to get a better match. So this is not bad, but for practice you could adjust the aspect ratio (increase the width), tweak the line widths and adjust the red and blue colors by modifying the RGB values for a better match.

Next I want to mention layout.  I made a second Canvas for the Sudan flag but I wasn’t able to separate it much below the first Canvas.  I’m not sure what is going on here, there’s an ‘offset’ parameter (line 32) but it doesn’t seem to work the way I think it should.  If anyone can help me figure out how to space these canvases I would appreciate it. To work around this I made a Frame and added a blank Label.  You can see the effect of this if you uncomment lines 37-41.  Change the text in line 40 to the empty string (“”) to make it seamless.  Adjust pady (line 41) to adjust the spacing.  But this is an awkward kludge, there should be a good way to do it with the Canvas configurations but I can’t figure it out yet.

OK, the Sudanese flag ... I made one pass at changing the red and green colors but it’s still not very close.  Change them for practice.  Note the use of the .create_polygon method.