Download presentation
Presentation is loading. Please wait.
1
Tkinter User Input Form
2
Planning We need to plan out an input form for a person to create a username for an online account The form has to have A suitable title A heading Input areas for username, first name and surname A button to submit details A button to clear the details from the form A Python program then has to confirm what was entered
3
.grid layout Your form should look a bit like this;
4
.grid layout So our plan will look like this
5
.grid layout So our structure will consist of
A window (the root) to contain all the form Frame 1 that will hold the form name Frame 2 that will hold rows for each type of input box (three of them – username, 1st name, last name) The next row outside of the frames will hold two buttons, 1 in each column
6
Import tkinter from tkinter import *
7
Submit function def submit(): print(“Username”,username.get()) print(“First name”,firstname.get()) print(“Surname”,surname.get())
8
Clear function def clear(): username.delete(0, END) firstname.delete(0, END) surname.delete(0, END) username.focus_set()
9
The window root = Tk() root.geometry(“270x240”) root.title(“Student Details”) root.resizable(False,False) root.configure(background = “Light Blue”)
10
Setting up the frames #the heading frame frame_heading = Frame(root) frame_heading.grid(row = 0, column=0, columnspan=2, padx=30, pady=5) #the data entry frame frame_entry = Frame(root) frame_entry.grid(row = 1, column=0, columnspan=2, padx=25, pady=10)
11
Frame 1 #entering the details for the frame_heading
Label(frame_heading, text = “Student Details Form”, font = (‘Arial’, 16)).grid(row = 0, column = 0, padx = 0, pady = 5)
12
Frame2 – column 0 (labels)
Label(frame_entry, text = “Username: ”).grid(row = 0, column = 0, padx = 10, pady = 5) Label(frame_entry, text = “First Name: ”).grid(row = 1, column = 0, padx = 10, pady = 5) Label(frame_entry, text = “Surname: ”).grid(row = 2, column = 0, padx = 10, pady = 5)
13
Frame2 – column 1 (input boxes)
username = Entry(frame_entry, width =15, bg = “white”) username.grid(row = 0, column = 1, padx = 5, pady = 5) firstname = Entry(frame_entry, width =15, bg = “white”) firstname.grid(row = 1, column = 1, padx = 5, pady = 5) surname = Entry(frame_entry, width =15, bg = “white”) surname.grid(row = 2, column = 1, padx = 5, pady = 5)
14
Placing the buttons submit_button = Button(root, text=“Submit”, width = 7, command=submit) submit_button.grid(row=2, column=0, padx=0, pady=5) clear_button = Button(root, text=“Clear”, width = 7, command=clear) clear_button.grid(row=2, column=1, padx=0, pady=5)
15
To get it running root.mainloop()
16
To improve this, we could also copy the delete function onto the end of the submit function, so that when we submitted our details, it clears the form ready for the next person’s details to be input.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.