0% found this document useful (0 votes)
4 views6 pages

Python Day9 Notes

This document provides an overview of GUI programming using Tkinter in Python for kids, covering essential concepts such as widgets, layout managers, and mini project examples. It explains how to create a basic application window, use various widgets like buttons and text entries, and manage layout with methods like pack, grid, and place. Additionally, it includes sample mini projects such as a simple calculator and a digital clock to reinforce learning.

Uploaded by

Madhu Mitha
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views6 pages

Python Day9 Notes

This document provides an overview of GUI programming using Tkinter in Python for kids, covering essential concepts such as widgets, layout managers, and mini project examples. It explains how to create a basic application window, use various widgets like buttons and text entries, and manage layout with methods like pack, grid, and place. Additionally, it includes sample mini projects such as a simple calculator and a digital clock to reinforce learning.

Uploaded by

Madhu Mitha
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Python for Kids - Day 9: GUI Programming with Tkinter | Widgets | Layout Managers | Mini Projects | CSC Institute

Python for Kids


DAY 9 - Class Notes
GUI Programming with Tkinter | Widgets | Layout Managers | Mini Projects
CSC Institute | Student Name: _______________________

GUI GUI Programming with Tkinter

What is Tkinter?
Tkinter is Python's built-in library for creating GUI (Graphical User Interface) applications.
GUI means programs with windows, buttons, input boxes - not just text in a terminal.
Examples: Calculator | Login Form | Student Form | Notepad | Digital Clock
Import: from tkinter import *
Every Tkinter program needs root = Tk() at the start and [Link]() at the end.

Line Code What it does


Import from tkinter import * Load all Tkinter widgets and tools
Window root = Tk() Create the main application window
Title [Link]("My App") Set the window title bar text
Size [Link]("300x200") Set window width x height in pixels
Run [Link]() Start the window event loop (keeps it open)

WIDGET Tkinter Widgets

What is a Widget?
A widget is a GUI element -- things you can see and interact with in a window.
Each widget is created by calling its class with the parent window as first argument.
Place it using pack() grid() or place() after creating it.

Widget Code Purpose


Label Label(root, text="Hello") Display static text or image
Button Button(root, text="Click", Clickable button that calls a function

Page 1
Python for Kids - Day 9: GUI Programming with Tkinter | Widgets | Layout Managers | Mini Projects | CSC Institute

command=fn)
Entry Entry(root) Single-line text input box
Text Text(root, height=5, width=20) Multi-line text input area
Checkbutton Checkbutton(root, Tick-box for yes/no selection
text="Python")
Radiobutton Radiobutton(root, variable=v, Select one option from a group
value=1)
Listbox Listbox(root) Scrollable list of items
Frame Frame(root) Container to group other widgets
messagebox [Link]("Title","M Pop-up dialog box
sg")

▶ Widget Programs

01. First Tkinter Window 02. Label Widget


from tkinter import * from tkinter import *

root = Tk() root = Tk()


[Link]("My Window") label = Label(root, text="Hello
[Link]("300x200") Tkinter")
[Link]() [Link]()
[Link]()

03. Button Widget 04. Entry Widget


from tkinter import * from tkinter import *

root = Tk() root = Tk()


btn = Button(root, text="Click Me") entry = Entry(root)
[Link]() [Link]()
[Link]() [Link]()

05. Button with Function 06. Get Entry Value


from tkinter import * from tkinter import *
root = Tk()
root = Tk() e = Entry(root)
[Link]()
def show():
print("Button Clicked") def data():
print([Link]())
btn = Button(root, text="Submit",
command=show) btn = Button(root, text="Show",
[Link]() command=data)
[Link]() [Link]()
[Link]()

07. Text Widget 08. Checkbutton


from tkinter import * from tkinter import *

Page 2
Python for Kids - Day 9: GUI Programming with Tkinter | Widgets | Layout Managers | Mini Projects | CSC Institute

root = Tk() root = Tk()


text = Text(root, height=5, width=20) c = Checkbutton(root, text="Python")
[Link]() [Link]()
[Link]() [Link]()

09. Radiobutton 10. Listbox


from tkinter import * from tkinter import *
root = Tk() root = Tk()
v = IntVar() listbox = Listbox(root)
r1 = Radiobutton(root, text="Male", [Link](1, "Python")
variable=v, value=1) [Link](2, "Java")
r2 = Radiobutton(root, text="Female", [Link]()
variable=v, value=2) [Link]()
[Link]()
[Link]()
[Link]()

LAYOUT Layout Managers

How to Arrange Widgets?


After creating a widget, you must place it using a layout manager.
pack() - simplest; stacks widgets top to bottom (or side by side)
grid() - places widgets in rows and columns like a table
place() - places widget at exact x, y pixel position
Never mix pack() and grid() in the same window!

Manager Syntax Best for


pack() [Link]() Simple top-to-bottom or side-by-side
layouts
grid() [Link](row=0, column=1) Form layouts with labels and input
boxes
place() [Link](x=100, y=50) Exact pixel positioning on the window

▶ Layout Manager & messagebox Programs

01. Message Box 02. grid() Layout


from tkinter import * from tkinter import *
from tkinter import messagebox
root = Tk() root = Tk()
Label(root, text="Name").grid(row=0,
def msg(): column=0)
[Link]("Info", Entry(root).grid(row=0, column=1)
"Welcome") [Link]()

Page 3
Python for Kids - Day 9: GUI Programming with Tkinter | Widgets | Layout Managers | Mini Projects | CSC Institute

btn = Button(root, text="Show",


command=msg)
[Link]()
[Link]()

03. place() Layout


from tkinter import *

root = Tk()
btn = Button(root, text="Login")
[Link](x=100, y=50)
[Link]("300x200")
[Link]()

Useful Widget Options


text - the text shown on Label, Button, Checkbutton, Radiobutton
command - function to call when Button is clicked
font - set font and size: font=("Arial", 14)
bg / fg - background colour / foreground (text) colour
width / height - size of the widget in characters (Entry, Text) or pixels
show - character to mask Entry input: show="*" for passwords
variable - linked variable for Checkbutton and Radiobutton
get() - reads current value from Entry widget
config() - update a widget property after creation: [Link](text=new)

PROJECT Sample Mini Projects

Project Overview
1. Simple Calculator - two Entry boxes, Add button prints sum
2. Login Form - username & password Entry, masked password
3. Student Registration Form - grid() layout with Name, Age, Submit
4. Temperature Converter - Enter Celsius, convert to Fahrenheit
5. Digital Clock - live clock using [Link]() to update every second

▶ Mini Project Programs

01. Simple Calculator 02. Login Form


from tkinter import * from tkinter import *
root = Tk() root = Tk()
e1 = Entry(root) Label(root, text="Username").pack()
e2 = Entry(root) user = Entry(root)
[Link]() [Link]()

Page 4
Python for Kids - Day 9: GUI Programming with Tkinter | Widgets | Layout Managers | Mini Projects | CSC Institute

[Link]() Label(root, text="Password").pack()


pwd = Entry(root, show="*")
def add(): [Link]()
a = int([Link]()) Button(root, text="Login").pack()
b = int([Link]()) [Link]()
print(a + b)

Button(root, text="Add",
command=add).pack()
[Link]()

03. Student Registration Form 04. Temperature Converter


from tkinter import * from tkinter import *
root = Tk() root = Tk()
Label(root, text="Name").grid(row=0, e = Entry(root)
column=0) [Link]()
Entry(root).grid(row=0, column=1)
Label(root, text="Age").grid(row=1, def convert():
column=0) c = float([Link]())
Entry(root).grid(row=1, column=1) f = (c * 9/5) + 32
Button(root, print(f)
text="Submit").grid(row=2, column=1)
[Link]()
Button(root, text="Convert",
command=convert).pack()
[Link]()

05. Digital Clock


from tkinter import *
import time
root = Tk()
label = Label(root, font=("Arial",
30))
[Link]()

def clock():
current = [Link]("%H:%M:
%S")
[Link](text=current)
[Link](1000, clock)

clock()
[Link]()

Quick Summary
Topic Meaning Key Code
Tkinter Python GUI library from tkinter import *
Tk() Create main window root = Tk()

Page 5
Python for Kids - Day 9: GUI Programming with Tkinter | Widgets | Layout Managers | Mini Projects | CSC Institute

mainloop() Keep window running [Link]()


Label Display text Label(root, text="Hello")
Button Clickable action Button(root, text="Go", command=fn)
Entry Single-line text input Entry(root) / [Link]()
Text Multi-line text area Text(root, height=5, width=20)
Checkbutton Tick box yes/no Checkbutton(root, text="Python")
Radiobutton Single choice from group Radiobutton(root, variable=v, value=1)
pack() Auto arrange top to [Link]()
bottom
grid() Row and column layout [Link](row=0, column=1)
place() Exact pixel position [Link](x=100, y=50)
messagebox Pop-up dialog [Link]("T", "Msg")
after() Repeat after delay (ms) [Link](1000, clock)

Happy Coding! - CSC Institute

Page 6

You might also like