# -*- coding: utf-8 -*- # These import statements import the module, but not the individual functions, # to call an individual function you now use : <>.<> # # Example: tkMessageBox.showinfo( .... ) # # This helps to clarify where different functions come from! # import tkMessageBox import tkSimpleDialog def messageBoxes(): tkMessageBox.showinfo(title="Game Over Info", message="This is an info dialog box!") tkMessageBox.showwarning(title="Game Over Warning", message="This is a warning dialog box") tkMessageBox.showerror(title="Game Over Error", message="This is an error dialog box") def questionExamples(): ans = tkMessageBox.askyesno("Continue", "Should I continue?") print ans # Answer will be True or False, so use it in an if statement if ans: print "We should continue" else: print "We should NOT continue" ans = tkMessageBox.askokcancel("Ok or not", "I'm continuing") print ans ans = tkMessageBox.askretrycancel("retry or not", "Retry?") print ans ans = tkMessageBox.askquestion("To be or not to be?", "Do you like CS112?\nReally what do you think?") print ans # What is different here... it is no longer True/False! # A little string formatting example ans = tkMessageBox.askquestion("String Formats", "You didn't forget string formatting".center(50) + "\n"+ "Did you?".center(50)+ "\n"+ "Because there is so much you can do with it...".center(50)+ "\n"+ "I would remember it if I was you".center(50)) print ans # What is different here... it is no longer True/False! def entryDialogs(): ans = None ans = tkSimpleDialog.askstring("Title", "Give me your name") print ans ans = tkSimpleDialog.askinteger("Int", "Give me an integer") print ans ans = tkSimpleDialog.askinteger("Int", "Give me an integer between 0 and 100", minvalue=0, maxvalue=100) print ans def main(): messageBoxes() questionExamples() entryDialogs() main()