0% found this document useful (0 votes)
295 views

Tkinter Examples

This document provides 10 examples of simple GUI programs in Python using the tkinter module. The examples are intended as teaching tools to demonstrate basic GUI concepts like buttons, labels, user input, and callbacks. The programs can be downloaded but students are encouraged to type them in themselves to better learn how to build simple GUI applications in Python.

Uploaded by

radebp
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
295 views

Tkinter Examples

This document provides 10 examples of simple GUI programs in Python using the tkinter module. The examples are intended as teaching tools to demonstrate basic GUI concepts like buttons, labels, user input, and callbacks. The programs can be downloaded but students are encouraged to type them in themselves to better learn how to build simple GUI applications in Python.

Uploaded by

radebp
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Simple GUI Program Examples with Python 3

Author: Rebecca DCruz


Email: [email protected]
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/

You might also like