- LPU MCA Semester 1
- CAB106
- Unit 6
CAB106 · Unit 6: Application development using OOP
Model-view concept and GUI using Tkinter
11 practice questions
Key points
- Model holds data, view displays, controller connects them
- Tk() is the main window and mainloop() starts the event loop
- pack, grid and place are the geometry managers
- Button command takes a function without brackets
The model-view idea separates what the program knows from how it is shown. The model holds data and rules, the view displays them, and a controller turns user actions (clicks, key presses) into model changes and view updates. Keeping them apart lets you change the interface without touching the logic, and a model can notify several views when it changes (the observer pattern).
Tkinter is Python's standard GUI toolkit. A program creates the root window with Tk(), adds widgets such as Label, Button, Entry (one line of input) and Frame (a container), arranges them with a geometry manager (pack, grid or place), and finally calls mainloop(), which starts the event loop that waits for user actions. A Button's command option takes a function without brackets; writing command=handler() would call it at once. StringVar, IntVar and DoubleVar hold values that linked widgets watch and update.
| Piece | Role |
|---|---|
Tk() | Main window |
Entry | Single-line text input |
grid | Row and column layout |
mainloop() | Starts the event loop |
Exam trap: pass command=handler, not command=handler(), and always end the program with mainloop() or the window closes immediately.
Try two questions
Which three geometry managers does Tkinter provide for laying out widgets?
- row, column and table
- pack, grid and place
- pack, align and stack
- grid, flow and border
Show the answer
B. Widgets are arranged with pack, grid or place.
Why not A: Those are layout terms, not Tkinter manager names.
Why not C: align and stack are not Tkinter managers.
Why not D: flow and border are layout managers of other toolkits.
In the model-view concept, which part holds the application's data and rules?
- The view
- The controller
- The event loop
- The model
Show the answer
D. The model owns the data and logic, the view shows it and the controller connects them.
Why not A: The view only displays the data.
Why not B: The controller passes user actions between the view and the model.
Why not C: The event loop waits for events and does not store application data.