[go: up one dir, main page]

0% found this document useful (0 votes)
423 views3 pages

QUIZZ Tkinter

Uploaded by

LOUNDOU orthega
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
423 views3 pages

QUIZZ Tkinter

Uploaded by

LOUNDOU orthega
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Pr.

Rym NASSIH L-CS

QUIZZ TKINTER

Question 1: What is the primary purpose of Tkinter in Python?


• (a) To create web applications
• (b) To build graphical user interfaces (GUIs)
• (c) To perform data analysis
• (d) To manage databases

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 4: How can you add functionality to a button in Tkinter?


• (a) By linking it to a command using the action parameter
• (b) By linking it to a function using the callback parameter
• (c) By linking it to a function using the command parameter
• (d) By embedding code inside the button widget

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)

Question 8: Which widget can display an image in Tkinter?


• (a) Label
• (b) Entry
Pr. Rym NASSIH L-CS

• (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

Question 12: What does the following code do?


from tkinter import *

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.

Question 13: What will happen if the following code is executed?


from tkinter import *

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()

button = Button(root, text="Print Text", command=print_text)


button.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.

Question 16: What does the following code display?


from tkinter import *

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.

You might also like