QUIZZ Tkinter
QUIZZ Tkinter
QUIZZ TKINTER
Question 2: Which of the following is used to create the main application window in Tkinter?
• (a) tk.Window()
• (b) tk.Toplevel()
• (c) tk.Tk()
• (d) tk.Screen()
Question 3: Which widget is used to display a one-line text input field in Tkinter?
• (a) Entry
• (b) Label
• (c) Text
• (d) Button
Question 5: What is the primary purpose of geometry managers like pack(), grid(), and place()?
• (a) To manage the size of widgets
• (b) To define the layout and position of widgets in the window
• (c) To handle the interactions of widgets
• (d) To apply styles to widgets
Question 6: What method is used to bind an event (like a key press) to a widget in Tkinter?
• (a) add_event()
• (b) bind_event()
• (c) bind()
• (d) on_event()
Question 7: How do you attach a menu bar to the main Tkinter window?
• (a) root.add(menu_bar)
• (b) menu_bar.config(root)
• (c) root.set_menu(menu_bar)
• (d) root.config(menu=menu_bar)
• (c) Text
• (d) Scrollbar
Question 9: Which option is used to set the background color of a button in Tkinter?
• (a) bg
• (b) background
• (c) color
• (d) button_color
Question 10: What method is used to start the Tkinter event loop?
• (a) root.run()
• (b) root.mainloop()
• (c) root.execute()
• (d) root.start()
Question 11: Which of the following widgets is used for multi-line text input?
• (a) Entry
• (b) Text
• (c) Label
• (d) Frame
root = Tk()
root.geometry("400x300")
root.title("My First Window")
root.mainloop()
• (a) Creates a window with a title and dimensions.
• (b) Displays a button labeled "My First Window".
• (c) Prints "My First Window" in the console.
• (d) Creates a canvas widget in a 400x300 window.
root = Tk()
label = Label(root, text="Hello, Tkinter!")
label.pack()
root.mainloop()
• (a) Displays a button with the text "Hello, Tkinter!".
• (b) Creates a window but does not display anything.
• (c) Displays a label with the text "Hello, Tkinter!" in the window.
• (d) Raises an error because label.pack() is not called correctly.
Question 14: What will the following code display when the button is clicked?
from tkinter import *
Pr. Rym NASSIH L-CS
def on_click():
print("Button clicked!")
root = Tk()
button = Button(root, text="Click Me", command=on_click)
button.pack()
root.mainloop()
• (a) Displays "Button clicked!" inside the window.
• (b) Displays "Button clicked!" in the console.
• (c) Raises an error because on_click is not called with parentheses.
• (d) Does nothing when the button is clicked.
Question 15: What will the following code print if the user enters "Tkinter" in the entry field and
clicks the button?
from tkinter import *
def print_text():
print(entry.get())
root = Tk()
entry = Entry(root)
entry.pack()
root.mainloop()
• (a) Prints "Print Text" in the console.
• (b) Prints "Tkinter" in the console.
• (c) Raises an error because entry.get() is not defined.
• (d) Prints nothing when the button is clicked.
root = Tk()
Label(root, text="Name:").grid(row=0, column=0)
Entry(root).grid(row=0, column=1)
Label(root, text="Age:").grid(row=1, column=0)
Entry(root).grid(row=1, column=1)
root.mainloop()
• (a) Displays two labels but no entry fields.
• (b) Displays two entry fields but no labels.
• (c) Displays a form with "Name" and "Age" labels next to their entry fields.
• (d) Raises an error because grid() cannot be used with labels and entry fields together.