Search Header Logo
Python GUI

Python GUI

Assessment

Presentation

Computers

7th - 8th Grade

Practice Problem

Medium

Created by

Mark Christensen

Used 8+ times

FREE Resource

17 Slides • 16 Questions

1

​Creating GUIs with Python

2

What is a GUI?

A GUI (graphical user interface) is a system of interactive visual components for computer software. A GUI displays objects that convey information, and represent actions that can be taken by the user. The objects change color, size, or visibility when the user interacts with them.

media

3

How do you pronounce GUI?

​GUI is often pronounced by saying each letter (G-U-I or gee-you-eye). It sometimes is also pronounced as "gooey."

media

4

Multiple Choice

What does GUI stand for?

1

graphical user interface

2

game under inspection

3

graphing unit intercept

4

graphic undergoing improvement

5

​GUI Example

​A GUI includes GUI objects, like icons, cursors, and buttons. These graphical elements are sometimes enhanced with sounds, or visual effects like transparency and drop shadows. Using these objects, a user can use the computer without having to know commands.

media

6

Multiple Choice

What word do we use to describe all of the grapical elements of an interactive computer program?

1

Button

2

Function

3

GUI

4

Python

7

What are the elements of a GUI?

To make a GUI as user-friendly as possible, there are different elements and objects that the user use to interact with the software.

media

8

What are the elements of a GUI?

Button - A graphical representation of a button that performs an action in a program when pressed

Dialog box - A type of window that displays additional information, and asks a user for input.

Icon - Small graphical representation of a program, feature, or file.

Menu - List of commands or choices offered to the user through the menu bar.

9

What are the elements of a GUI?

Menu bar - Thin, horizontal bar containing the labels of menus.

Tab - Clickable area at the top of a window that shows another page or area.

Toolbar - Row of buttons, often near the top of an application window, that controls software functions.

Window - Rectangular section of the computer's display that shows the program currently being used.​

10

Multiple Choice

Which of the follow is NOT an element of a GUI?

1

Button

2

Window

3

Dialog box

4

If statement

11

Importing Tkinter

To get started, we'll first need to start by importing Tkinter. We will start by creating a window then we will learn how to add widgets such as buttons, combo boxes, etc, then we will play with their properties​.

Importantly, the code used to create a GUI is a loop. All of your widgets, properties, and functions need to be inside the main loop. IT CANNOT BE BELOW THE MAIN LOOP LINE.

12

Importing Tkinter

media
media

​Adding this code...

​Looks like this...

13

Multiple Choice

The program we are writing is contained inside of a Loop. This means...

1

We cannot add code below the main loop line

2

The window will keep opening and closing

3

We cannot add buttons

4

Adding code anywhere is fine

14

Adding Lables

To add a label to our previous example, we will create a label using the label class like this:

media

​We can set its position on the window by using the place command and x/y coordinates

15

Multiple Choice

Which code determines the placement of the label?

1

lbl.place(x=0, y=0)

2

text="Hello"

3

fg="red"

4

font=20

16

Multiple Choice

Which code determines what the label says?

1

lbl.place(x=0, y=0)

2

text="Click here"

3

fg="red"

4

font=20

17

Adding Buttons

We can add a button to our code in a similar way that we added lables. The one difference is that buttons have a configure option called "command".​ Command is the function that runs when you click on the button. The command window.destroy closes the entire window.

media

18

Multiple Choice

Which line of code runs a function when the button is clicked?

1

command =

2

text =

3

font =

4

place(x=0, y=0)

19

Coding a function for the button

We can ​create functions that run when you click a button. These functions will be important for making our buttons actually do things when clicked. These functions can change settings and appearances, get text from user input, and make our app interactive.

20

Multiple Select

What types of things can we code a function to do when a button is clicked?

(Select all that apply)

1

Change app settings and appearances

2

Get text from user input

3

Make the app interactive

21

Coding a function for the button

media
media

​These are two examples of possible functions you could create. Notice how both codes use the configure line of code to adjust settings when the button is clicked.

22

Multiple Choice

What type of code makes a button do things when it is clicked?

1

Print statement

2

Input

3

Function

4

List

23

Coding a function for the button

​Using the configure line of code allows us to change the appearance and settings of various widgets in the app.

lbl.configure​ - adjusts the lable (lbl)

window.configure - adjusts the window​

media

24

Multiple Select

Question image

Which line or lines of code change the color of the window?

(Select all that apply)

1

47

2

48

3

51

4

52

5

53

25

Multiple Select

Question image

Which line or lines of code change what the label says?

(Select all that apply)

1

47

2

48

3

51

4

52

5

53

26

​Most apps and programs will require user input to be interactive. Sometimes a user will have to type in their name, address, or even a password.

Getting User Input

media

​To allow user input, we will need a text entry field. When creating a text entry field you will need to specify the width and the placement.

27

​Once we have created a text input field, we can create a function that gets the user input and uses it.

Getting User Input

media

​The txt.get( ) command gets the text that the user input

The txt.delete(0, END) command deletes all of the text in the text entry field​

28

Getting User Input

media

​Putting it all together, we can create a password entry system

29

Multiple Choice

Question image

Which type of code can get the user input to use in your program?

1

txt.get( )

2

txt.delete( )

3

txt.place( )

4

text = "This is a label"

30

Multiple Choice

Question image

If you want to clear the text entry field and make it empty, what type of code should you utilize?

1

txt.get( )

2

txt.delete( )

3

txt.place( )

4

text = "This is a label"

31

Multiple Select

Question image

Which types of code did we use to create a password entry system?

(Select all that apply)

1

If/Else

2

Function

3

List

4

Variable

32

Multiple Choice

Question image

True or False

The attached image is an example of a GUI that you could create with all of the code mentioned previously.

1

True

2

False

33

Match

Match the following

Requires a function to work when clicked

Uses text from a text entry field

Changes what a label looks like

This can be used to keep track of clicks or other data

Determines the positioning of widgets in your app

Button

txt.get( )

lbl.configure

Variable

place(x= ,y= )

​Creating GUIs with Python

Show answer

Auto Play

Slide 1 / 33

SLIDE