TOC A. Menu B. Tab A. Menu Most GUI applications have menu bar to provide many features. Menu bar include several menus , and ...
TOC
A. Menu
Most GUI applications have menu bar to provide many features. Menu bar include several menus, and they are trigger for each feature.
- File
Image 1
- Help
Image 2
- Line 3: import Menu from tkinter
- Line 5: defines the actions for Exit menu. destroy() close the window. Because exit() terminates jupyter server or python shell, it is commented out here.
- Line 13: defines menu. It will be used as a menu bar.
- Line 14: register menu bar to win.
- Line 16: defines menu which will be used as File. tearoff represents the dash line between parent menu and child menu. In this case, it is False, so it is not shown. However, Help menu has it.
- Line 17: add child menu which is New.
- Line 18: add separator between New and Exit.
- Line 19: add child menu which is Exit. It has callback function, _quit.
- Line 20: register File menu to menu bar.
- Line 22: define next menu which will be used as Help.
- Line 23: add child menu which is About.
- Line 24: register Help menu to menu bar.
B. Tab
Tab is an useful widget to share space. Tab can allow us to overlap each other. In tkinter, tab is implemented with frame.
- Tab 1
Image 3
- Tab 2
Image 4
- Line 7: defines notebook. Notebook is a frame for tab.
- Line 9: defines tab 1.
- Line 13: register tab 1 to notebook.
- Line 15: defines tab 2.
- Line 19: register tab 2 to notebook.
COMMENTS