# Here are a few commonly asked Tkinter interview questions
# along with their possible answers
# Q1: What is Tkinter?
# A1: Tkinter is a Python library used for creating GUI applications. It provides a set of tools and functions to build windows, dialogs, buttons, menus, etc.
# Q2: How to create a basic Tkinter window?
# A2:
import tkinter as tk
# Create the main window
window = tk.Tk()
# Set the window title
window.title("My Tkinter Window")
# Start the event loop
window.mainloop()
# Q3: How to add a button to a Tkinter window?
# A3:
import tkinter as tk
def button_clicked():
print("Button clicked!")
window = tk.Tk()
# Create a button widget
button = tk.Button(window, text="Click Me", command=button_clicked)
# Display the button
button.pack()
window.mainloop()
# Q4: How to create a dialog box in Tkinter?
# A4:
import tkinter as tk
from tkinter import messagebox
window = tk.Tk()
def messagebox_clicked():
messagebox.showinfo("Dialog Box", "This is a dialog box.")
button = tk.Button(window, text="Open Dialog Box", command=messagebox_clicked)
button.pack()
window.mainloop()
# Q5: How to handle button clicks in Tkinter?
# A5:
import tkinter as tk
window = tk.Tk()
def button_clicked():
print("Button clicked!")
button = tk.Button(window, text="Click Me", command=button_clicked)
button.pack()
window.mainloop()
# These are just a few examples; there can be many more questions and answers related to Tkinter for interviews.