Home »
MCQs
PyGTK MCQs (Multiple-Choice Questions)
PyGTK is a Python binding for the GTK+ graphical user interface toolkit. It provides Python developers with access to GTK+ widgets, containers, dialogs, menus, signals, and other components for creating desktop graphical applications.
PyGTK MCQs
This section contains PyGTK Multiple-Choice Questions with Answers. These PyGTK MCQs cover important concepts such as widgets, windows, containers, signals, callbacks, buttons, text controls, menus, dialogs, layouts, and the GTK main loop. Practice these MCQs to test and improve your knowledge of PyGTK.
List of PyGTK MCQs
The following are the popular MCQs on PyGTK:
1. What is PyGTK primarily used for?
- Developing web servers
- Creating graphical user interfaces
- Managing databases
- Processing audio files
Answer: B) Creating graphical user interfaces
Explanation:
PyGTK provides Python bindings for the GTK+ toolkit and is used to create desktop graphical user interfaces. It provides widgets and other components required for building GUI applications.
2. Which module is commonly imported when developing an application with PyGTK?
- pygui
- gtk
- pygtkui
- gtkpython
Answer: B) gtk
Explanation:
The gtk module provides the higher-level GTK+ widgets used by PyGTK applications.
import gtk
3. Which statement was commonly used to request PyGTK 2.x compatibility?
- pygtk.version('2.0')
- pygtk.require('2.0')
- gtk.require('2.0')
- gtk.version('2.0')
Answer: B) pygtk.require('2.0')
Explanation:
In PyGTK 2.x applications, pygtk.require('2.0') was commonly used to request the PyGTK 2.0 API before importing the gtk module.
import pygtk
pygtk.require('2.0')
import gtk
4. Which class represents a top-level window in PyGTK?
- gtk.Window
- gtk.TopWindow
- gtk.MainWindow
- gtk.FrameWindow
Answer: A) gtk.Window
Explanation:
gtk.Window represents a top-level window in PyGTK. It can contain child widgets and provides the main window for many GUI applications.
5. Which function starts the GTK main event loop?
- gtk.start()
- gtk.run()
- gtk.main()
- gtk.event_loop()
Answer: C) gtk.main()
Explanation:
The gtk.main() function starts the GTK main loop. The main loop processes events generated by user interactions and other sources.
gtk.main()
6. Which function is used to terminate the current GTK main loop?
- gtk.stop()
- gtk.main_quit()
- gtk.exit()
- gtk.quit_loop()
Answer: B) gtk.main_quit()
Explanation:
The gtk.main_quit() function terminates the current level of the GTK main loop.
gtk.main_quit()
7. Which method is used to make a PyGTK widget visible?
- display()
- show()
- visible()
- open()
Answer: B) show()
Explanation:
The show() method makes a widget visible. It is commonly used when constructing a PyGTK interface.
8. Which method recursively displays a widget and its child widgets?
- show_children()
- show_all()
- display_all()
- show_widgets()
Answer: B) show_all()
Explanation:
The show_all() method recursively shows a widget and its child widgets. It is particularly useful after adding several child widgets to a container.
window.show_all()
9. Which method is used to hide a PyGTK widget?
- hide()
- remove()
- close()
- invisible()
Answer: A) hide()
Explanation:
The hide() method hides a widget without necessarily destroying it.
10. Which class is used to create a push button in PyGTK?
- gtk.PushButton
- gtk.Button
- gtk.ClickButton
- gtk.CommandButton
Answer: B) gtk.Button
Explanation:
The gtk.Button class creates a standard push button. A button can contain a label or another widget and can emit a signal when activated.
11. Which signal is commonly associated with clicking a gtk.Button?
- pressed
- clicked
- selected
- activated_button
Answer: B) clicked
Explanation:
The clicked signal is emitted when a gtk.Button is activated by the user.
12. Which method is used to connect a signal to a callback function?
- connect()
- attach()
- bind_signal()
- register()
Answer: A) connect()
Explanation:
The connect() method is used to associate a GTK signal with a callback function.
button.connect("clicked", callback)
13. What is a callback function in PyGTK?
- A function executed in response to an event or signal
- A function that creates a Python package
- A function used only for drawing images
- A function that starts the operating system
Answer: A) A function executed in response to an event or signal
Explanation:
A callback is a function that is invoked when a connected signal or event occurs. For example, a button's clicked signal can call a callback function.
14. Which class is commonly used to display a text label in PyGTK?
- gtk.TextLabel
- gtk.Label
- gtk.StaticText
- gtk.Caption
Answer: B) gtk.Label
Explanation:
The gtk.Label widget displays text in a PyGTK application.
15. Which class provides a single-line text entry control in PyGTK?
- gtk.TextBox
- gtk.Entry
- gtk.Input
- gtk.Edit
Answer: B) gtk.Entry
Explanation:
The gtk.Entry widget provides a single-line text entry field.
16. Which method retrieves the text currently contained in a gtk.Entry?
- get_text()
- read_text()
- get_value()
- read_value()
Answer: A) get_text()
Explanation:
The get_text() method returns the text currently contained in a gtk.Entry widget.
17. Which method sets the text of a gtk.Entry?
- set_value()
- set_text()
- write_text()
- put_text()
Answer: B) set_text()
Explanation:
The set_text() method changes the text displayed in a gtk.Entry.
entry.set_text("Hello")
18. Which widget is suitable for entering multiple lines of text?
- gtk.Entry
- gtk.TextView
- gtk.TextField
- gtk.MultiEntry
Answer: B) gtk.TextView
Explanation:
gtk.TextView is designed for displaying and editing multi-line text. It normally works with a gtk.TextBuffer that stores the text.
19. Which object stores the text displayed or edited by a gtk.TextView?
- gtk.TextStore
- gtk.TextBuffer
- gtk.TextData
- gtk.TextModel
Answer: B) gtk.TextBuffer
Explanation:
A gtk.TextBuffer stores the text and related information used by a gtk.TextView.
20. Which class is the base class for PyGTK widgets?
- gtk.Control
- gtk.Widget
- gtk.GUIObject
- gtk.Component
Answer: B) gtk.Widget
Explanation:
gtk.Widget is the base class for GTK widgets. Many commonly used interface controls inherit directly or indirectly from this class.
21. Which container is used to arrange child widgets horizontally or vertically?
- gtk.Box
- gtk.GridBox
- gtk.LayoutBox
- gtk.PanelBox
Answer: A) gtk.Box
Explanation:
gtk.Box is a container used to arrange child widgets in a single row or column depending on its orientation.
22. Which class is commonly used for a horizontal box in PyGTK?
- gtk.HBox
- gtk.HorizontalBox
- gtk.HContainer
- gtk.RowBox
Answer: A) gtk.HBox
Explanation:
gtk.HBox is the PyGTK 2.x container traditionally used to arrange child widgets horizontally.
23. Which class is used to arrange child widgets vertically in PyGTK?
- gtk.VBox
- gtk.VerticalBox
- gtk.VContainer
- gtk.ColumnBox
Answer: A) gtk.VBox
Explanation:
gtk.VBox is traditionally used in PyGTK 2.x to arrange child widgets vertically.
24. Which method adds a widget to a container?
- add()
- insert_widget()
- attach_widget()
- append_widget()
Answer: A) add()
Explanation:
The add() method is used by container widgets to add a child widget. For example, a window can contain a single child widget using add().
window.add(button)
25. Which method is commonly used to add a child widget to a gtk.Box?
- pack_start()
- add_child()
- insert_start()
- append_widget()
Answer: A) pack_start()
Explanation:
The pack_start() method is used to add a child to the beginning of a box container. Its parameters can control properties such as expansion and padding.
26. Which method adds a child widget to the end of a gtk.Box?
- pack_end()
- add_end()
- append_end()
- insert_end()
Answer: A) pack_end()
Explanation:
The pack_end() method adds a child widget at the end of a box container.
27. Which container arranges widgets in rows and columns?
- gtk.Table
- gtk.RowColumn
- gtk.GridContainer
- gtk.Matrix
Answer: A) gtk.Table
Explanation:
In PyGTK 2.x, gtk.Table is a container that arranges child widgets in a table-like structure consisting of rows and columns.
28. Which method is used to attach a widget to a gtk.Table?
- attach()
- add_at()
- place()
- insert_table()
Answer: A) attach()
Explanation:
The attach() method is used to place a child widget within specified rows and columns of a gtk.Table.
29. Which widget provides a list of selectable choices in PyGTK?
- gtk.Choice
- gtk.ComboBox
- gtk.SelectBox
- gtk.OptionList
Answer: B) gtk.ComboBox
Explanation:
gtk.ComboBox provides a control that allows the user to select an item from a list of choices.
30. Which widget provides a tabbed interface in PyGTK?
- gtk.TabView
- gtk.Notebook
- gtk.TabControl
- gtk.PageTabs
Answer: B) gtk.Notebook
Explanation:
gtk.Notebook is a tabbed container that allows multiple child pages to be displayed with tabs.
31. Which widget is used to create a menu bar in PyGTK?
- gtk.MenuBar
- gtk.MenuPanel
- gtk.MainMenu
- gtk.MenuContainer
Answer: A) gtk.MenuBar
Explanation:
The gtk.MenuBar widget displays menu items horizontally and is commonly placed at the top of an application window.
32. Which widget represents an individual menu in PyGTK?
- gtk.Menu
- gtk.MenuList
- gtk.SubMenu
- gtk.MenuBox
Answer: A) gtk.Menu
Explanation:
The gtk.Menu widget represents a menu that can contain menu items and submenus.
33. Which widget represents an item inside a PyGTK menu?
- gtk.MenuOption
- gtk.MenuItem
- gtk.ItemMenu
- gtk.MenuEntry
Answer: B) gtk.MenuItem
Explanation:
gtk.MenuItem represents an individual item in a menu. It can contain a label and can be associated with a callback.
34. Which widget is used to display a message dialog in PyGTK?
- gtk.MessageDialog
- gtk.MessageBox
- gtk.AlertDialog
- gtk.DialogMessage
Answer: A) gtk.MessageDialog
Explanation:
gtk.MessageDialog provides a convenient dialog for displaying messages and standard response buttons.
35. Which class is used to create a general-purpose dialog in PyGTK?
- gtk.Dialog
- gtk.PopupDialog
- gtk.GeneralDialog
- gtk.WindowDialog
Answer: A) gtk.Dialog
Explanation:
gtk.Dialog provides a general-purpose dialog window that can contain widgets and buttons for interacting with the user.
36. Which dialog is used to allow the user to select a file?
- gtk.FileDialog
- gtk.FileChooserDialog
- gtk.SelectFile
- gtk.FileWindow
Answer: B) gtk.FileChooserDialog
Explanation:
gtk.FileChooserDialog provides a dialog for selecting files or folders, depending on its configured action.
37. Which widget can be used to select a color in PyGTK?
- gtk.ColorChooser
- gtk.ColorButton
- gtk.ColorSelector
- gtk.ColorWidget
Answer: B) gtk.ColorButton
Explanation:
gtk.ColorButton is a button that allows the user to select a color through a color selection interface.
38. Which widget allows the user to select a date from a calendar?
- gtk.DatePicker
- gtk.Calendar
- gtk.DateChooser
- gtk.DaySelector
Answer: B) gtk.Calendar
Explanation:
gtk.Calendar is a widget that displays a calendar and allows the user to select a date.
39. Which widget is used to represent a selectable on/off option?
- gtk.CheckButton
- gtk.CheckBox
- gtk.ToggleCheck
- gtk.OptionButton
Answer: A) gtk.CheckButton
Explanation:
gtk.CheckButton provides a check button that can be selected or cleared by the user.
40. Which widget is used when the user should choose one option from a group of radio buttons?
- gtk.RadioButton
- gtk.OptionGroup
- gtk.SingleChoice
- gtk.RadioChoice
Answer: A) gtk.RadioButton
Explanation:
gtk.RadioButton creates a radio button. Radio buttons can be grouped so that one option can be selected from a set of related choices.
41. Which module provides lower-level window-system functionality in PyGTK?
- gtk.lowlevel
- gtk.gdk
- gtk.system
- gtk.windowapi
Answer: B) gtk.gdk
Explanation:
The gtk.gdk module provides lower-level functionality associated with the underlying windowing system. It contains objects and functions used below the higher-level GTK widget layer.
42. Which module provides text layout and rendering functionality in PyGTK?
- textgtk
- pango
- gtk.font
- gtk.textlayout
Answer: B) pango
Explanation:
The pango module provides access to the Pango text layout and rendering functionality used by GTK applications.
43. Which module in PyGTK provides accessibility-related functionality?
- access
- atk
- gtk.access
- pango.access
Answer: B) atk
Explanation:
The atk module provides access to the Accessibility Toolkit functionality used to support accessibility in GTK applications.
44. Which module was used in PyGTK to load interfaces from XML descriptions using libglade?
- gtk.xml
- gtk.glade
- gtk.builder
- gtk.ui
Answer: B) gtk.glade
Explanation:
The gtk.glade module provided access to libglade functionality for loading graphical user interfaces described in XML.
45. Which PyGTK class is used to build an interface from an XML UI definition?
- gtk.Builder
- gtk.XMLLoader
- gtk.InterfaceBuilder
- gtk.UIBuilder
Answer: A) gtk.Builder
Explanation:
gtk.Builder can construct an interface from an XML UI definition. It is a newer approach compared with the older libglade-based mechanism.
46. Which widget is used to display a horizontal or vertical separator?
- gtk.Separator
- gtk.SeparatorMenuItem
- gtk.Divider
- gtk.Line
Answer: A) gtk.Separator
Explanation:
gtk.Separator is the base class for separator widgets. PyGTK also provides specific horizontal and vertical separator widgets.
47. Which method can be used to set the title of a gtk.Window?
- set_caption()
- set_title()
- set_name()
- set_header()
Answer: B) set_title()
Explanation:
The set_title() method sets the title displayed by a gtk.Window.
window.set_title("My Application")
48. Which method can be used to set the default size of a PyGTK window?
- set_size()
- set_default_size()
- set_window_size()
- set_initial_size()
Answer: B) set_default_size()
Explanation:
The set_default_size() method sets the default width and height of a window.
window.set_default_size(400, 300)
49. Which signal is commonly connected to gtk.main_quit() to close an application window?
- delete-event
- close-window
- exit-event
- window-close
Answer: A) delete-event
Explanation:
The delete-event signal is commonly connected to a callback that calls gtk.main_quit(), allowing the application to terminate its main loop when the window is closed.
window.connect("delete-event", gtk.main_quit)
50. Which statement correctly creates a simple PyGTK button?
- button = gtk.PushButton("Hello")
- button = gtk.Button("Hello")
- button = gtk.Button.create("Hello")
- button = gtk.WidgetButton("Hello")
Answer: B) button = gtk.Button("Hello")
Explanation:
The gtk.Button constructor can receive a label as an argument. The following statement creates a button displaying the text "Hello".
button = gtk.Button("Hello")
Advertisement
Advertisement