-
Notifications
You must be signed in to change notification settings - Fork 2
HFP CH 8.5
(exceptions and message boxes)
19 Pages Long
Description: Yes this chapter is actually labeled as 8 1/2 not 9. This was a small chapter utilizing the code you wrote in Chapter 8. You learn about exception catches and messages as well as the importance of incorporating them into your code. Especially when building GUI's since you will not see the errors presented from the CLI.
The Code:
Small amount of code here. You build and create a few different kinds of exceptions on top of the code from Chapter 8. You look for the same issue,error, problem. An un writable file that should be. You simply display the exception a few different ways. Finally ending with a message box that requires acknowledgement from the user.
Main Concepts Covered:
- Some errors don't crash your program - they throw exceptions instead.
- You can run code when there's an exception - this is called "catching the exception."
- Code that runs because of an exception is called an exception handler.
- GUI message boxes display information and ask questions.
- Message boxes are also known as "dialog boxes."
- Message boxes require the user to respond, even if it is just to click the OK button.
Python Tools Covered:
- You can catch exceptions by using a
try
/except
block. -
except Exception as ex
will assign the exception message to a variable calledex
. - You can display the exception error message by formatting it as a string.
- To display message boxes,you need to import the
tkinter.messagebox
module. - Message boxes that display information are all called
show...()
. - Message boxes that ask questions are all called
ask...()
. - Message boxes return True if the response was OK,Yes, or Retry.
- Message boxes return False if the response was No.
- Message boxes return None if the response was Cancel.