Alerting the user

Finally, let's see the alerting logic. It's extremely simple:

def _sb(msg):
_status_msg.set(msg)

def _alert(msg):
messagebox.showinfo(message=msg)

That's it! To change the status bar message all we need to do is to access _status_msg StringVar, as it's tied to the _status label.

On the other hand, if we want to show the user a more visible message, we can fire up a message box. Here's how it should look on a mac:

The messagebox object can also be used to warn the user (messagebox.showwarning) or to signal an error (messagebox.showerror). But it can also be used to provide dialogs that ask us whether we're sure we want to proceed or if we really want to delete that file, and so on.

If you inspect messagebox by simply printing out what dir(messagebox) returns, you'll find methods such as askokcancel, askquestion, askretrycancel, askyesno, and askyesnocancel, as well as a set of constants to verify the response of the user, such as CANCEL, NO, OK, OKCANCEL, YES, and YESNOCANCEL. You can compare these to the user's choice so that you know the next action to execute when the dialog closes.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset