SDF-Week_17
SDF-Week_17
Note:
• Some of the slides of the course are based on the material provided
by the College of Technological Information, Zayed University, UAE.
• The copyrighted material belongs to their respective owners.
1
17/12/2024
Code Documentation
- The Python code must contain proper documentation.
- Suggested header documentations are provided for programs and functions.
Program Header Suggestion:
# Program/Class Name:
# Author(s):
# Date of Creation:
Function Header Suggestion:
# Function Description:
# Parameters:
# Return Type:
- All programs and all functions must contain sufficient documentation to explain
their intent and use.
• Simple is better than complex: When choosing between a simple and a complex
solution, always opt for the simple one if both work effectively. Simpler code is
easier to maintain, understand, and extend.
2
17/12/2024
• The tkinter library, is the only GUI framework that is built into the Python
standard library
import tkinter as tk
Window
• Create a window using import tkinter as tk
tkinter
# Create a window
window = tk.Tk()
• The module tkinter has
class Tk # Keeps focus on window till closed
window.mainloop()
• Standard window will
depend on the OS used
3
17/12/2024
Widgets
• Widgets are GUI elements inside a window
• Each widget in tkinter is defined by a class.
Label Widget
import tkinter as tk
# Create a window
window = tk.Tk()
4
17/12/2024
Button Widget
import tkinter as tk
# Create a window
window = tk.Tk()
# Create a window
window = tk.Tk()
window.mainloop() 10
10
5
17/12/2024
Text Widget
import tkinter as tk
# Create a window
window = tk.Tk()
11
11
12
12
6
17/12/2024
Activity
• Create a window, to ask the user for his Name, CIN, phone number,
and City.
• When the user clicks the “Save” button, clear the fields and print all
the information on the screen and to a text file.
13
13
In Summary
• GUI in Python
• Creating Window
• Adding Widgets
14
14