Tkinter Dialogs Dick Steflik CS 260 Menus Menu

  • Slides: 11
Download presentation
Tkinter - Dialogs Dick Steflik CS 260

Tkinter - Dialogs Dick Steflik CS 260

Menus Menu Bar or Action Bar Menus

Menus Menu Bar or Action Bar Menus

Menu Choices Common User Access CUA - IBM 1989 – Still followed by many

Menu Choices Common User Access CUA - IBM 1989 – Still followed by many OEM software providers. MS Office has started to deviate in the last two releases and is relying more on Toolbars. Action Choice – Performs some task immediately ( ex. Print, Save, Exit) Routing Choice – Displays a menu or secondary window, this usually accompanied by a visual cue ( … indicated a dialog ) Setting Choice - allows the user to display or change the characteristics or properties of the corresponding object. These choices usually have a visual cue (ex. wordwrap ; would be preceded by nothing if turned off or preceded by a checkmark if turned on) Menu choices may also contain text showing the keyboard shortcut to accomplish the action. (ex the keyboard short cut for ‘New’ is ctl+N )

Common Keyboard Shortcuts New Open Save Print Undo Cut Copy Paste Select all Help

Common Keyboard Shortcuts New Open Save Print Undo Cut Copy Paste Select all Help Refresh Rename Close ctl+N ctl+O ctl+S ctl+P ctl+Z ctl+X ctl+C ctl+V ctl+A F 1 F 5 F 2 ctl+W

Menu Example root = Tk() root. title(menubar) top = Menu(win) win. config = Menu(top)

Menu Example root = Tk() root. title(menubar) top = Menu(win) win. config = Menu(top) file. add_command(label=‘New ctl+N’ , command =notdone underline = 0) file. add_command(label=‘Save ctl+S’ , command =notdone underline = 0) file. add_command(label=‘Save as …’ , command =notdone underline = 0) file. add_command(label=‘Exit’ , command =notdone underline = 0) edit = Menu(top , rearoff=0) edit. add_command(label=‘Cut’ , command =notdone underline = 0) edit. add_command(label=‘Copy’ , command =notdone underline = 0) edit. add_command(label=‘Paste’ , command =notdone underline = 0) edit. add_seperator() edit. add_command(label=‘Replace…’ , command =notdone underline = 0)

Dialogs • Windows displayed to request additional information • Usually activated from a menu

Dialogs • Windows displayed to request additional information • Usually activated from a menu choice • Modal – block the GUI until completed. The user must dispatch/complete the dialog before continuing with the application • Non-modal – remains on screen in parallel with the GUI

Module tk. Message. Box showinfo(title=None, message=None, **options) Show an info message showwarning(title=None, message=None, **options)

Module tk. Message. Box showinfo(title=None, message=None, **options) Show an info message showwarning(title=None, message=None, **options) Show a warning message showerror(title=None, message=None, **options) Show an error message askquestion(title=None, message=None, **options) Ask a question askokcancel(title=None, message=None, **options) Ask if operation should proceed; return true if the answer is ok askyesno(title=None, message=None, **options) Ask a question; return true if the answer is yes askretrycancel(title=None, message=None, **options) Ask if operation should be retried; return true if the answer is yes

Common Dialogs askokcancel() showwarning() askyesno() showerror() showinfo()

Common Dialogs askokcancel() showwarning() askyesno() showerror() showinfo()

Module tk. File. Dialog askopenfile(mode=‘r’, **options) open a file aslopenfilename( **options) get a filename

Module tk. File. Dialog askopenfile(mode=‘r’, **options) open a file aslopenfilename( **options) get a filename to open asksaveafile(mode=‘w’, **options) save a file asksaveafilename( **options) get a file name to save askdirectory( ***options) choose a directory options: ** defaultextension, filetypes, initialdir, initialfile, multiple, message, parent, title *** initialdir, parent, title, mustexist

ask. Directory tk. File. Dialog. ask. Directory(parent=root, ’ initialdir=“/”, ”title’Pick a directory’)

ask. Directory tk. File. Dialog. ask. Directory(parent=root, ’ initialdir=“/”, ”title’Pick a directory’)

tk. Color. Chooser. ask. Color() result = tk. Color. Chooser. ask. Color ( color,

tk. Color. Chooser. ask. Color() result = tk. Color. Chooser. ask. Color ( color, option=value, . . . ) clicking OK returns a tuple (triple, color) there triple is r, g, b as three integers (0 -255) clicking Cancel returns (none, none)