Skip to content

HFP CH 8.5

Jacob Amey edited this page Aug 19, 2013 · 1 revision

Chapter 8.5 - Get the message?

(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:

  1. Some errors don't crash your program - they throw exceptions instead.
  2. You can run code when there's an exception - this is called "catching the exception."
  3. Code that runs because of an exception is called an exception handler.
  4. GUI message boxes display information and ask questions.
  5. Message boxes are also known as "dialog boxes."
  6. 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 called ex.
  • 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.
Clone this wiki locally