TKINTER GUI GRAPHICAL USER INTERFACE Makes a program

  • Slides: 24
Download presentation
TKINTER GUI GRAPHICAL USER INTERFACE

TKINTER GUI GRAPHICAL USER INTERFACE

Makes a program easier to use EXPLANATIO N Allows you to create screens Allows

Makes a program easier to use EXPLANATIO N Allows you to create screens Allows you to create text boxes Allows you to create buttons Helps user navigate easier

TKINTER • This is a library of features in Python

TKINTER • This is a library of features in Python

KEYWORDS window. geometr y Allows you to set the size of the box button.

KEYWORDS window. geometr y Allows you to set the size of the box button. place Allows you to set the coordinates of where it appears in the box You can set its width and height

RESERVED/KEYWORDS

RESERVED/KEYWORDS

LABEL & TEXT • Shows text to user • Shows multiple lines of text

LABEL & TEXT • Shows text to user • Shows multiple lines of text

BUTTON & • Creates a button that runs a subprogram ENTRY • Gets input

BUTTON & • Creates a button that runs a subprogram ENTRY • Gets input from a user

MESSAGE • Displays multiline text fields & LISTBOX • Displays a list of items

MESSAGE • Displays multiline text fields & LISTBOX • Displays a list of items

CANVAS USED TO DRAW SHAPES AND FIGURES

CANVAS USED TO DRAW SHAPES AND FIGURES

CODING EXAMPLES

CODING EXAMPLES

window. geometry this sets the window size and title window = Tk() window. title(“Number

window. geometry this sets the window size and title window = Tk() window. title(“Number List”) window. geometry(“ 400 x 200”)

BUTTON creates a message in the button and when pressed will run a subprogram

BUTTON creates a message in the button and when pressed will run a subprogram button 1 = Button(text = “Add to List” command = add_number) messag e subprogram

BUTTON. PLACE sets the location, height, & width of the button 1. place(x =

BUTTON. PLACE sets the location, height, & width of the button 1. place(x = 250, y = 20, width = 100, height = 25)

DEFINING THE add_number(): FUNCTION def add_number(): num = num_box. get() if num. isdigit(): num_list.

DEFINING THE add_number(): FUNCTION def add_number(): num = num_box. get() if num. isdigit(): num_list. insert(END, num) num_box. delete(0, END) num_box. focus() else: num_box. delete(0, END) num_box. focus()

DEFINING THE clear_list(): FUNCTION def clear_list(): clear_list. delete(0, END) num_box. focus()

DEFINING THE clear_list(): FUNCTION def clear_list(): clear_list. delete(0, END) num_box. focus()

LABEL adds text to the screen displaying a message label 1 = Label(text =

LABEL adds text to the screen displaying a message label 1 = Label(text = “Enter a number: “)

LABEL. PLACE sets the location and size of the label 1. place(x = 20,

LABEL. PLACE sets the location and size of the label 1. place(x = 20, y = 20, width = 100, height = 25)

ENTRY creates a blank entry box num_box = Entry(text = 0)

ENTRY creates a blank entry box num_box = Entry(text = 0)

PLACING AN ENTRY BOX num_box. place(x = 120, y = 20, width = 100,

PLACING AN ENTRY BOX num_box. place(x = 120, y = 20, width = 100, height = 25) num_box. focus()

CREATING A LIST BOX num_list = Listbox() num_list. place(x = 120, y = 50,

CREATING A LIST BOX num_list = Listbox() num_list. place(x = 120, y = 50, width = 100, height = 100)

CREATE A ND 2 BUTTON creates a message in the button and when pressed

CREATE A ND 2 BUTTON creates a message in the button and when pressed will run a subprogram button 2 = Button(text = “Clear List” command = clear_list) button 2. place(x = 250, y = 50, width = 100, height = 25)

MISC.

MISC.

THIS LINE MUST GO AT THE BEGINNING OF THE PROGRAM TO IMPORT THE TKINTER

THIS LINE MUST GO AT THE BEGINNING OF THE PROGRAM TO IMPORT THE TKINTER LIBRARY from Tkinter import *

THIS MUST BE AT THE END OF THE PROGRAM TO MAKE SURE IT KEEPS

THIS MUST BE AT THE END OF THE PROGRAM TO MAKE SURE IT KEEPS WORKING window. mainloop()