You are on page 1of 13

Simple GUI Program Examples with Python 3

Author: Rebecca DCruz


Email: rebecca@d-cruz.me.uk
Version: 1.2
Date: 4th January 2017

These examples demonstrate the use of Pythons tkinter module. It is intentional that neither the Tk
themed widget set (ttk) module nor an Object Oriented approach is used. They are intended as
teaching examples for exploration and extension.

Programs can be downloaded from http://tinyurl.com/tkinter-rdcruz but it is not recommended that


this is passed on to students as they will learn more by typing the programs in and adapting them.

Contents
Example 1: Hello GUI! .................................................................................................................................... 2
Example 2: Button with a callback function .................................................................................................. 3
Example 3: A button and label ...................................................................................................................... 4
Example 4: Reading user input ...................................................................................................................... 5
Example 5: Simple guessing game ................................................................................................................. 6
Example 6: Guessing game with reset button and global variables.............................................................. 7
Example 7: Password checking using * masking ........................................................................................ 9
Example 8: Pig Latin one word only.......................................................................................................... 11
Example 9: Pig Latin phrases .................................................................................................................... 12
Example 10: Dynamic GUI generation with lambda functions.................................................................... 13

Page 1 of 13

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
http://creativecommons.org/licenses/by-nc-sa/4.0/
Simple GUI Program Examples with Python 3

Example 1: Hello GUI!

Page 2 of 13

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
http://creativecommons.org/licenses/by-nc-sa/4.0/
Simple GUI Program Examples with Python 3

Example 2: Button with a callback function

Page 3 of 13

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
http://creativecommons.org/licenses/by-nc-sa/4.0/
Simple GUI Program Examples with Python 3

Example 3: A button and label

Page 4 of 13

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
http://creativecommons.org/licenses/by-nc-sa/4.0/
Simple GUI Program Examples with Python 3

Example 4: Reading user input

Page 5 of 13

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
http://creativecommons.org/licenses/by-nc-sa/4.0/
Simple GUI Program Examples with Python 3

Example 5: Simple guessing game

Page 6 of 13

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
http://creativecommons.org/licenses/by-nc-sa/4.0/
Simple GUI Program Examples with Python 3

Example 6: Guessing game with reset button and global variables

Page 7 of 13

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
http://creativecommons.org/licenses/by-nc-sa/4.0/
Simple GUI Program Examples with Python 3

Page 8 of 13

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
http://creativecommons.org/licenses/by-nc-sa/4.0/
Simple GUI Program Examples with Python 3

Example 7: Password checking using * masking

Page 9 of 13

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
http://creativecommons.org/licenses/by-nc-sa/4.0/
Simple GUI Program Examples with Python 3

Page 10 of 13

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
http://creativecommons.org/licenses/by-nc-sa/4.0/
Simple GUI Program Examples with Python 3

Example 8: Pig Latin one word only

Page 11 of 13

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
http://creativecommons.org/licenses/by-nc-sa/4.0/
Simple GUI Program Examples with Python 3

Example 9: Pig Latin phrases

Page 12 of 13

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
http://creativecommons.org/licenses/by-nc-sa/4.0/
Simple GUI Program Examples with Python 3

Example 10: Dynamic GUI generation with lambda functions

Page 13 of 13

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License
http://creativecommons.org/licenses/by-nc-sa/4.0/