Courseiva

CCNA Graphical User Interface Programming Questions

44 questions · Graphical User Interface Programming · All types, answers revealed

1
MCQhard

You are implementing a GUI where a long-running calculation is performed upon clicking a button. To prevent the GUI from freezing (not responding), what is the best practice approach?

A.Call root.update() inside the calculation loop.
B.Increase the root.after() delay time.
C.Wrap the calculation in a try-except block within the button command.
D.difficulty
E.Use the threading module to run the calculation in a separate thread.
AnswerE

Offloading the task to a background thread keeps the main thread free to process GUI events.

Why this answer

Running blocking operations in the main thread freezes the event loop; threading is required to keep the GUI responsive.

2
MCQhard

When binding an event to a widget using 'widget.bind('<Key>', handler)', the handler function receives an event object. How do you access the specific character pressed?

A.handler(event.char)
B.handler(event.keysym)
C.handler(event.get_char())
D.handler(event.key)
E.difficulty
AnswerA

The 'char' attribute is the correct way to retrieve the character associated with the keyboard event.

Why this answer

The event object passed to the handler contains the 'char' attribute which holds the character pressed.

3
Multi-Selectmedium

Which TWO of the following events are commonly bound in Tkinter for mouse interaction?

Select 2 answers
A.<Enter>
B.<Button-1>
C.<Quit>
D.<KeyPress>
E.<MouseMove>
AnswersA, B

Represents the mouse cursor entering the widget area.

Why this answer

<Button-1> (click) and <Enter> (mouse over) are standard mouse events.

4
Multi-Selectmedium

Which THREE of the following are valid states for a Tkinter widget?

Select 3 answers
A.readonly
B.disabled
C.normal
D.active
E.hidden
AnswersB, C, D

The state where interaction is blocked.

Why this answer

normal, disabled, and active are valid states for many Tkinter widgets.

5
MCQhard

When using the place() geometry manager, what is the purpose of 'relx' and 'rely'?

A.Relative position as a float from 0 to 1.
B.Relative font size.
C.Relative pixel coordinates.
D.Relative Z-index for layering.
AnswerA

They define position relative to the container size.

Why this answer

They represent the position of the widget as a fraction of the parent container's width and height (0.0 to 1.0).

6
MCQhard

When using the pack geometry manager, you want a widget to fill the available space in the parent container. Which argument for the 'fill' parameter should you use to make it expand in both horizontal and vertical directions?

A.fill=tk.BOTH
B.fill='all'
C.fill='both'
D.fill=tk.EXPAND
AnswerA

tk.BOTH is the correct constant for filling both directions.

Why this answer

The 'BOTH' constant from the tkinter module is used with the fill parameter to expand in both dimensions.

7
Multi-Selecthard

Which TWO of the following are valid ways to add padding to a widget in the grid layout?

Select 2 answers
A.margin=10
B.spacing=10
C.gap=10
D.padx=10
E.pady=10
AnswersD, E

Adds horizontal padding.

Why this answer

padx and pady are the correct parameters for adding spacing around a widget in the grid.

8
MCQhard

How do you access the value of a StringVar associated with an Entry widget?

A.var.retrieve()
B.var.content()
C.var.get()
D.var.value
AnswerC

get() is the correct method to access the value.

Why this answer

The get() method is used on the StringVar object to retrieve its current value.

9
MCQeasy

You need to add a label that displays static text in your GUI. Which widget is most appropriate for this purpose?

A.tk.Message()
B.tk.Entry()
C.tk.Display()
D.tk.Label()
E.tk.Text()
AnswerD

Label is the standard widget for displaying text.

Why this answer

The Label widget is designed specifically for displaying non-editable text or images.

10
Multi-Selecthard

Which TWO of the following statements about the 'grid' geometry manager are correct?

Select 2 answers
A.It requires absolute pixel positioning.
B.It only supports a single column layout.
C.It allows widgets to span across multiple rows or columns.
D.It uses row and column indices to position widgets.
E.It cannot be mixed with the pack manager in the same parent.
AnswersC, D

rowspan and columnspan allow for spanning.

Why this answer

Grid allows for row/column spanning and absolute positioning within cells, but it is a row/column based system, not absolute XY.

11
MCQeasy

You want to create a button that closes the GUI application when clicked. Which method should you call inside the command callback?

A.root.destroy()
B.root.close()
C.root.exit()
D.root.quit()
AnswerA

destroy() is the standard way to close a window.

Why this answer

The destroy() method on the root window object terminates the Tkinter application.

12
MCQmedium

You wish to group several widgets together within a frame. Which widget acts as a container for this purpose?

A.tk.Group()
B.tk.Box()
C.tk.Container()
D.tk.Frame()
AnswerD

Frame is the standard container widget.

Why this answer

The Frame widget is specifically designed as a container to group other widgets.

13
MCQeasy

You are creating a simple Tkinter application and notice that your window does not appear on the screen after calling the Tk() constructor. Which method must be called to start the event loop?

A.root.show()
B.root.render()
C.root.mainloop()
D.root.run()
AnswerC

mainloop() is the essential method to keep the GUI responsive.

Why this answer

The mainloop() method is required to start the Tkinter event loop, which listens for events and updates the display.

14
MCQmedium

You have a Checkbutton and you need to track its state. What is the recommended way to associate a variable with the Checkbutton?

A.Use the 'onvalue' parameter.
B.Pass a BooleanVar object to the 'variable' parameter.
C.Use the state attribute directly.
D.Use the 'command' parameter to set a global flag.
AnswerB

Variable objects allow for dynamic tracking of widget values.

Why this answer

A BooleanVar or IntVar should be passed to the 'variable' parameter of the Checkbutton.

15
MCQhard

When using the grid layout manager, which option allows a column to grow when the window is resized?

A.root.grid_grow(column=0, weight=1)
B.root.columnconfigure(0, weight=1)
C.root.grid_column(0, resizable=True)
D.root.set_grid(0, expand=True)
AnswerB

columnconfigure with weight > 0 makes the column resizable.

Why this answer

The columnconfigure() method is used to set the weight of a column, allowing it to expand.

16
Multi-Selectmedium

Which TWO of the following methods are commonly used to update a Tkinter widget's state or appearance dynamically?

Select 2 answers
A.widget.rebind()
B.widget.reload()
C.widget.refresh()
D.widget.config(state='disabled')
E.widget.insert(END, 'text')
AnswersD, E

config() is the primary method to modify widget attributes.

Why this answer

The config() method and specific widget methods like insert() are standard for updates.

17
MCQeasy

Which widget is most appropriate if you need to display a read-only multi-line block of text to the user?

A.difficulty
B.Text
C.Message
D.Entry
E.Label
AnswerB

The Text widget supports multiple lines and can be made read-only by setting its state.

Why this answer

The Text widget is standard for multi-line text, and setting 'state' to 'disabled' makes it read-only.

18
MCQmedium

You have a list of options and want the user to select one using a dropdown menu. Which widget should you use?

A.tk.ComboBox()
B.tk.Select()
C.tk.Dropdown()
D.tk.OptionMenu()
AnswerD

OptionMenu is the correct class for dropdowns.

Why this answer

The OptionMenu widget is the standard tool for creating a dropdown selection list.

19
MCQmedium

You want to create a Menu that contains sub-menus. Which class or method is used to add a sub-menu to an existing menu?

A.difficulty
B.menu.add_menu()
C.menu.add_cascade()
D.menu.add_command()
E.menu.add_submenu()
AnswerC

add_cascade links a sub-menu object to a menu item.

Why this answer

The add_cascade method is used to create a menu item that opens a sub-menu.

20
Multi-Selectmedium

Which THREE of the following are valid parameters for the pack() layout manager?

Select 3 answers
A.row
B.expand
C.column
D.side
E.fill
AnswersB, D, E

Specifies whether to take up extra space.

Why this answer

side, fill, and expand are standard parameters for the pack() manager.

21
MCQmedium

Which widget is most appropriate for displaying a list of selectable items?

A.tk.Checkbutton()
B.tk.Listbox()
C.tk.OptionMenu()
D.tk.Menu()
AnswerB

Listbox is the correct widget for a list of items.

Why this answer

The Listbox widget is intended for displaying a list of strings that the user can select.

22
Multi-Selecteasy

Which TWO of the following are valid geometry managers in Tkinter?

Select 2 answers
A.pack
B.block
C.align
D.flow
E.grid
AnswersA, E

pack is a standard geometry manager.

Why this answer

pack, grid, and place are the three built-in geometry managers in Tkinter.

23
Multi-Selecthard

Which THREE of the following widgets are part of the 'ttk' (Themed Tkinter) module?

Select 3 answers
A.ttk.Entry
B.ttk.Button
C.ttk.Label
D.ttk.Window
E.ttk.Canvas
AnswersA, B, C

Themed entry widget.

Why this answer

ttk.Button, ttk.Label, and ttk.Entry are part of the themed widget set, whereas standard tkinter widgets are in the top-level tkinter module.

24
MCQeasy

Which module must be imported to utilize Tkinter in a Python script?

A.import tkinter
B.import gui
C.from python import gui
D.import tk
AnswerA

This is the correct module name.

Why this answer

The 'tkinter' module is the standard Python interface to the Tk GUI toolkit.

25
MCQeasy

You have a Button widget and want to trigger a function named 'process_data' when the user clicks it. Which is the standard way to associate the function with the button?

A.button = Button(root, event=process_data)
B.button.bind('<Button-1>', process_data)
C.button = Button(root, command=process_data)
D.button.set_action(process_data)
AnswerC

The 'command' parameter is designed specifically for triggering functions on button clicks.

Why this answer

The 'command' parameter is the standard way to bind a callback function to a button click event.

26
MCQmedium

In a Tkinter grid layout, you want a button to span across two columns. Which parameter should you use?

A.columnspan=2
B.span_cols=2
C.merge=2
D.cols=2
AnswerA

columnspan is the correct parameter for merging grid columns.

Why this answer

The columnspan parameter in the grid() method manager allows a widget to occupy multiple columns.

27
MCQmedium

You are building a Tkinter application and need to ensure that a Label widget expands to fill any extra horizontal space when the parent window is resized. Which configuration for the grid() layout manager achieves this?

A.widget.pack(fill='x', expand=True)
B.widget.grid(sticky='nsew')
C.widget.grid(padx=10, pady=10)
D.parent.columnconfigure(0, weight=1) and widget.grid(sticky='ew')
AnswerD

Setting the column weight allows expansion, and sticky='ew' forces the widget to fill that space.

Why this answer

The sticky parameter with 'ew' (east and west) ensures the widget stretches horizontally, while columnconfigure with weight > 0 allows the column to expand.

28
MCQeasy

What is the correct way to specify the title of a Tkinter window?

A.root.set_title('My App')
B.root.title('My App')
C.root.name = 'My App'
D.root.set_header('My App')
AnswerB

title() sets the window header text.

Why this answer

The title() method is called on the root window object.

29
MCQhard

Which method on a widget instance causes it to be removed from the display, but not destroyed?

A.widget.hide()
B.widget.remove()
C.widget.delete()
D.widget.pack_forget()
AnswerD

pack_forget() removes the widget from the display.

Why this answer

The pack_forget() (or grid_forget()) method hides a widget from the layout manager.

30
Multi-Selectmedium

Which THREE of the following are valid ways to configure a widget's appearance after it has been created?

Select 3 answers
A.widget['bg'] = 'blue'
B.widget.config(bg='blue')
C.widget.configure(bg='blue')
D.widget.set_bg('blue')
E.widget.style = 'blue'
AnswersA, B, C

Dictionary-style access is supported for configuration.

Why this answer

Widget appearance can be configured via the config() method, using dictionary-style access, or by directly calling attribute-specific methods if they exist (though config is standard).

31
Multi-Selectmedium

Which TWO of the following statements correctly describe the behavior of the Tkinter 'pack' geometry manager?

Select 2 answers
A.The manager automatically ignores the order in which pack() is called.
B.The 'side' parameter can be set to 'top', 'bottom', 'left', or 'right'.
C.Widgets are placed in a grid coordinate system.
D.Widgets are positioned at exact X and Y coordinates.
E.The 'fill' parameter can be set to 'x', 'y', 'both', or 'none'.
AnswersB, E

These are the valid values for the 'side' parameter.

Why this answer

Pack stacks widgets based on the 'side' argument and 'fill' determines how they occupy available space.

32
MCQhard

You want to trigger a function when a user releases a key. Which event string should you use with bind()?

A.<Key-Up>
B.<ReleaseKey>
C.<KeyUp>
D.<KeyRelease>
AnswerD

<KeyRelease> is the correct event string.

Why this answer

The '<KeyRelease>' event is used to detect when a key is released.

33
Multi-Selecthard

Which THREE of the following are valid ways to pass arguments to a function called by a Tkinter button command?

Select 3 answers
A.command=lambda arg=arg1: my_func(arg)
B.command=lambda: my_func(arg1)
C.command=functools.partial(my_func, arg1)
D.command=my_func(arg1=value)
E.command=my_func(arg1)
AnswersA, B, C

Using default arguments in a lambda is a robust way to capture values.

Why this answer

Using lambda or functools.partial are the standard ways to handle arguments in button commands.

34
MCQmedium

You are using the pack() geometry manager and want to place a frame at the bottom of the window, ensuring it stays there even when other widgets are added. Which configuration is correct?

A.frame.pack(side='bottom', fill='x')
B.frame.pack(anchor='s', expand=True)
C.frame.pack(side='bottom', expand=False)
D.difficulty
E.frame.grid(row=99, column=0)
AnswerA

This anchors the frame to the bottom and makes it expand horizontally.

Why this answer

The 'side' parameter set to 'bottom' and 'fill' set to 'x' is the standard way to anchor a widget to the bottom edge.

35
MCQeasy

Which widget is most suitable for displaying multi-line, editable text?

A.tk.Listbox()
B.tk.Entry()
C.tk.Text()
D.tk.Label()
AnswerC

Text is for multi-line text.

Why this answer

The Text widget provides a flexible, multi-line text area.

36
MCQeasy

Which attribute of a Button widget controls the text displayed on it?

A.value
B.text
C.caption
D.label
AnswerB

text is the attribute for the button label.

Why this answer

The 'text' parameter defines the display label of the button.

37
Multi-Selecteasy

Which THREE of the following are valid Tkinter variable classes used for tracking widget states?

Select 3 answers
A.FloatVar
B.IntVar
C.CharVar
D.StringVar
E.BooleanVar
AnswersB, D, E

Used for integer values.

Why this answer

StringVar, IntVar, DoubleVar, and BooleanVar are the standard Tkinter variable classes.

38
MCQmedium

You need a color chooser dialog in your application. Which module contains this functionality?

A.tkinter.dialogs
B.tkinter.colorchooser
C.tkinter.colors
D.tkinter.widgets
AnswerB

This module contains the color selection dialog.

Why this answer

The 'tkinter.colorchooser' module provides the askcolor() function.

39
Multi-Selecteasy

Which TWO of the following are valid ways to terminate a Tkinter script gracefully?

Select 2 answers
A.os.kill()
B.root.quit()
C.exit()
D.root.close()
E.root.destroy()
AnswersB, E

Correctly exits the event loop.

Why this answer

Calling destroy() on the root window or calling the quit() method are standard ways to end a GUI session.

40
MCQeasy

What is the primary function of the 'bg' parameter in a widget configuration?

A.Sets the button group.
B.Sets the border group.
C.Sets the background color.
D.Sets the base grid.
AnswerC

bg stands for background.

Why this answer

The 'bg' (or background) parameter sets the background color of the widget.

41
MCQhard

To prevent a user from editing text in a widget, which configuration option should you set?

A.editable=False
B.enabled=False
C.state=tk.DISABLED
D.readonly=True
AnswerC

state=tk.DISABLED effectively makes the widget uneditable.

Why this answer

Setting 'state' to 'disabled' prevents user interaction with the widget.

42
MCQmedium

You want to bind a function 'on_click' to a left mouse button click on a Button widget. Which event sequence string is correct?

A.<Button-1>
B.<Mouse-1>
C.<Left-Click>
D.<Click-1>
AnswerA

<Button-1> represents the left mouse click.

Why this answer

The event sequence '<Button-1>' corresponds to the primary (left) mouse button.

43
MCQmedium

How do you set a specific font for a widget?

A.widget.set_font('Arial', 12)
B.widget.style('Arial', 12)
C.widget.font = 'Arial 12'
D.widget.config(font=('Arial', 12))
AnswerD

The font parameter is the standard way to set typography.

Why this answer

The 'font' parameter accepts a tuple or string defining font family, size, and style.

44
MCQhard

You have a Tkinter Entry widget and want to retrieve the text currently entered by the user. Which method do you call on the Entry instance?

A.entry.get()
B.entry.content()
C.entry.text()
D.entry.value()
AnswerA

get() is the correct method to extract the string content from an Entry widget.

Why this answer

The get() method is used to retrieve the current contents of Entry and Text widgets.

Ready to test yourself?

Try a timed practice session using only Graphical User Interface Programming questions.