Introduction to Programming Using Python, Y. Daniel Liang

Many questions in this edition have been updated in the new edition. Please check with the publisher on the newest edition.

This quiz is for students to practice. A large number of additional quiz is available for instructors using Quiz Generator from the Instructor's Resource Website. Videos for Java, Python, and C++ can be found at https://yongdanielliang.github.io/revelvideos.html.

Chapter 9 GUI Programming Using Tkinter


Sections 9.2-9.4
9.1  How do you create a window?
A. window = newWindow()
B. window = Window()
C. window = Frame()
D. window = Tk()

9.2  How do you create a frame?
A. frame = newWindow()
B. frame = Window()
C. frame = Frame()
D. frame = Tk()

9.3  How do you create an event loop?
A. window.loop()
B. window.main()
C. window.mainloop()
D. window.eventloop()

9.4  To create a label under parent window, use _______.
A. label = Label(text = "Welcome to Python")
B. label = Label(window, text = "Welcome to Python")
C. label = Label(text = "Welcome to Python", fg = " red")
D. label = Label(text = "Welcome to Python", fg = " red", bg = "white")

9.5  To create a button under parent window with command processButton, use _______.
A. Button(text = "OK", fg = "red", command = processButton)
B. Button(window, text = "OK", fg = "red")
C. Button(window, text = "OK", fg = "red")
D. Button(window, text = "OK", command = processButton)

9.6  Assume v1 = IntVar(), how do you set a new value 5 to v1.
A. v1 = 5
B. v1.setValue(5)
C. v1.set(5)
D. v1.get(5)

9.7  Assume v1 = IntVar(), how do you create a check button under parent frame1 with variable bound to v1?
A. Checkbutton(frame1, text = "Bold", command = processCheckbutton)
B. Checkbutton(frame1, text = "Bold", variable = v1.get())
C. Checkbutton(frame1, text = "Bold", variable = v1, command = processCheckbutton)
D. Checkbutton(frame1, text = "Bold", variable = v1.set(), command = processCheckbutton)

9.8  Assume v1 = IntVar(), how do you create a radio button under parent frame1 with variable bound to v1 and value 1?
A. Checkbutton(frame1, text = "Bold", command = processCheckbutton)
B. Checkbutton(frame1, text = "Bold", variable = v1.get())
C. Checkbutton(frame1, text = "Bold", variable = v1, command = processCheckbutton)
D. Radiobutton(frame1, text = "Yellow", bg = "yellow", variable = v1, value = 1, command = processRadiobutton)

9.9  Assume name = StringVar(), how do you create a text field (entry) under parent frame2 with variable bound to name?
A. entryName = Entry(frame2, textvariable = name)
B. entryName = Entry(frame2, variable = name, value = "")
C. entryName = Entry(frame2, textvariable = name, command = processEntry)
D. entryName = Entry(frame2, text = name, command = processEntry)

9.10  How do you create a GUI component for displaying multiple-lines of text?
A. use Label
B. Use Button
C. Use Text
D. Use Message

9.11  How do you create a text area?
A. use Label
B. Use Button
C. Use Text
D. Use Message

Section 9.5
9.12  How do you create a canvas under parent frame1 with background color white and foregroung color green?
A. Canvas(frame1, bg = "white", fg = "green")
B. Canvas(frame1, bg = "white", fg = "green", command = processEvent)
C. Canvas(frame1, bg = "white", command = processEvent)
D. Canvas(frame1, fg = "green", command = processEvent)

Section 9.5
9.13  How do you draw a rectangle centered at 100, 100 with width 100 and height 100 on canvas?
A. canvas.create_rect(100, 100, 100, 100)
B. canvas.create_rectangle(100, 100, 100, 100)
C. canvas.create_rect(100 - 50, 100 - 50, 100 + 50, 100 + 50)
D. canvas.create_rectangle(100 - 50, 100 - 50, 100 + 50, 100 + 50)

9.14  How do you draw a circle rectangle centered at 100, 100 with radius 100 on canvas?
A. canvas.create_oval(100, 100, 100, 100)
B. canvas.create_oval(100 - 100, 100 - 100, 100 + 100, 100 + 100)
C. canvas.create_oval(100 - 50, 100 - 50, 100 + 50, 100 + 50)
D. canvas.create_circle(100 - 100, 100 - 100, 100 + 100, 100 + 100)

9.15  How do you draw an arc centered at 100, 100 with radius 20, starting angle 15, ending angle 50, filled with red color on canvas?
A. canvas.create_arc(100 - 20, 100 - 20, 100 + 20, 100 + 20, fill = "red", start = 15, extent = 50)
B. canvas.create_arc(100 - 20, 100 - 20, 100 + 20, 100 + 20, fill = "red", start = 15, extent = 35)
C. canvas.create_arc(100 - 20, 100 - 20, 100 + 20, 100 + 20, filled = "red", start = 15, extent = 50)
D. canvas.create_arc(100 - 20, 100 - 20, 100 + 20, 100 + 20, fill = "red", start = 15, end = 50)

9.16  How do you draw a red line from 100, 100 to 400, 500?
A. canvas.create_line(100, 100, 100, 500, fill = "red")
B. canvas.create_line(100, 100, 400, 100, fill = "Red")
C. canvas.create_line(100, 100, 400, 500, filled = "red")
D. canvas.create_line(100, 100, 400, 500, fill = "red")

9.17  How do you draw a polygon consisting of points (30, 40), (50, 50), (10, 100) filled with red color?
A. canvas.create_poly(30, 40, 50, 50, 10, 100, fill = "red")
B. canvas.create_polygon(30, 40, 50, 50, 10, 100, filled = "red")
C. canvas.create_polygon(30, 40, 50, 50, 10, 100, fill = "red")
D. canvas.create_polygon((30, 40), (50, 50), (10, 100), fill = "red")

9.18  How do you display a text "Good morning" centered at 30, 40 with color red?
A. canvas.create_text(30, 40, text = "Good morning", fill = "red")
B. canvas.create_polygon(30, 40, 50, 50, 10, 100, filled = "red")
C. canvas.create_polygon(30, 40, 50, 50, 10, 100, fill = "red")
D. canvas.create_polygon((30, 40), (50, 50), (10, 100), fill = "red")

Section 9.6 The Geometry Managers
9.19  _______ are geometry managers in Tkinter.
A. pack
B. grid
C. place
D. flow

9.20  To place a button in a specified row and column in its parent container, use ________.
A. pack manager
B. grid manager
C. place manager
D. flow manager

9.21  Which option do you use to put the components in a container using the pack manager in the same row?
A. component.pack(LEFT)
B. component.pack(side = LEFT)
C. component.pack(side = "LEFT")
D. component.pack("LEFT")

9.22  The side option of the pack manager may be _____________.
A. LEFT
B. RIGHT
C. BOTTOM
D. TOP

9.23  Using a grid manager, you can use the option _________ to place a component in multiple rows and columns.
A. row
B. column
C. rowspan
D. columnspan

Section 9.8 Displaying Images
9.24  To create an image, use ______________________.
A. image = PhotoImage(imagefilename)
B. image = Image(file = imagefilename)
C. image = PhotoImage(file = imagefilename)
D. image = PhotoImage(imagefilename)

9.25  You can create an image from a ____________ file.
A. .png
B. .gif
C. .bmp
D. .jpg

9.26  You can display an image in ______________.
A. a label
B. a button
C. a check button
D. a radio button
E. an entry

Section 9.9 Menus
9.27  To create a menu in a window, use __________
A. menubar = Menu(window)
B. menubar = MenBar(window)
C. menubar = Menu()
D. menubar = MenBar()

9.28  To add a menu in a menubar, use __________
A. menu1 = Menu(menubar)
B. menu1 = menu(menubar)
C. menu1 = Menu(winodw)
D. menu1 = Menu()

9.29  To add a menubar, use __________
A. window.configure(menu = menubar)
B. window.config(menubar)
C. window.config(menu = menubar)
D. window.configure(menubar)

Sections 9.10-9.11
9.30  To display a popup menu, use __________
A. menu.display()
B. menu.post()
C. menu.display(300, 300)
D. menu.post(300, 300)

9.31  To bind a canvas with a left mouse click event p, use __________
A. canvas.left(p)
B. canvas.bind("<Button-1>", p)
C. canvas.bind("Button-1", p)
D. canvas.bind(<Button-1>, p)

9.32  To bind a canvas with a right mouse click event p, use __________
A. canvas.left(p)
B. canvas.bind("<Button-1>", p)
C. canvas.bind("Button-1", p)
D. canvas.bind(<Button-1>, p)
E. canvas.bind("<Button-3>", p)

9.33  To bind a canvas with a mouse entered event p, use __________
A. canvas.entered(p)
B. canvas.bind("<Enter>", p)
C. canvas.bind("<Entered>", p)
D. canvas.bind(<Enter>, p)

9.34  The event _____________ is fired when the mouse is moved while the middle mouse is being held down.
A. <B1-Motion>
B. <B2-Motion>
C. <B3-Motion>
D. <Button-1>
E. <Button-2>

9.35  The event _____________ is fired when the right mouse button is released.
A. <ButtonReleased-1>
B. <ButtonReleased-2>
C. <ButtonReleased-3>
D. <ButtonPressed-1>
E. <ButtonPressed-2>

9.36  The event _____________ is fired when the right mouse button is double-clicked.
A. <Double-Button-1>
B. <Double-Button-2>
C. <Double-Button-3>
D. <Triple-Button-1>
E. <Triple-Button-2>

9.37  To bind a canvas with a key event p, use __________
A. canvas.entered(p)
B. canvas.bind("<Enter>", p)
C. canvas.bind("<Key>", p)
D. canvas.bind(<Enter>, p)
E. canvas.bind("<Enter>", p)

9.38  The mouse event object has the property ____________.
A. x
B. y
C. widget
D. X
E. Y

Section 9.14 Standard Dialogs
9.39  To display a message dialog named "Programming is fun", use __________
A. tkinter.messagebox.showinfo("showinfo", "Programming is fun")
B. tkinter.messagebox.showwarning("showwarning", "Programming is fun")
C. tkinter.messagebox.showerror("showerror", "Programming is fun")
D. tkinter.messagebox.askyesno("ashyesno", "Programming is fun")

9.40  To display a warning dialog named "Variable is assigned, but not used", use __________
A. tkinter.messagebox.showinfo("showinfo", "Variable is assigned, but not used")
B. tkinter.messagebox.showwarning("showwarning", "Variable is assigned, but not used")
C. tkinter.messagebox.showerror("showerror", "PVariable is assigned, but not used")
D. tkinter.messagebox.askyesno("ashyesno", "Variable is assigned, but not used")

9.41  To display an error dialog named "Variable is not assigned", use __________
A. tkinter.messagebox.showinfo("showinfo", "Variable is not assigned")
B. tkinter.messagebox.showwarning("showwarning", "Variable is not assigned")
C. tkinter.messagebox.showerror("showerror", "Variable is not assigned")
D. tkinter.messagebox.askyesno("ashyesno", "Variable is not assigned")

9.42  To display an input dialog named "Is this an integer?", use __________
A. tkinter.messagebox.showinfo("showinfo", "Is this an integer?")
B. tkinter.messagebox.showwarning("showwarning", "Is this an integer?")
C. tkinter.messagebox.showerror("showerror", "Is this an integer?")
D. tkinter.messagebox.askyesno("ashyesno", "Is this an integer?")