0% found this document useful (0 votes)
14 views

Bca Gui Final Assignment2024

Uploaded by

Dipali Gaikwad
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)
14 views

Bca Gui Final Assignment2024

Uploaded by

Dipali Gaikwad
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/ 13

1.

Label Widget
Question: Write a Python program to display a label using
Tkinter.

import tkinter as tk
root = tk.Tk()
root.title("Label Example")
label = tk.Label(root, text="Hello, BCA Students!")
label.pack()
root.mainloop()

Expected Output:
A window appears with a label displaying the text "Hello,
BCA Students!"
2. Button Widget
Question: Write a Python program to create a button that
displays a message when clicked.

import tkinter as tk
from tkinter import messagebox
root = tk.Tk()
root.title("Button Example")
def show_message():
messagebox.showinfo("Button Clicked", "Button was
clicked!")
button = tk.Button(root, text="Click Me",
command=show_message)
button.pack()
root.mainloop()

Expected Output:
A window with a button labeled "Click Me." When
clicked, a message box appears showing "Button was
clicked!"

3. Entry Widget
Question: Write a Python program to display an Entry
widget and retrieve user input.
import tkinter as tk
root = tk.Tk()
root.title("Entry Example")
entry = tk.Entry(root)
entry.pack()
def get_input():
entered_text = entry.get()
print("Entered text:", entered_text)

button = tk.Button(root, text="Get Input",


command=get_input)
button.pack()
root.mainloop()

Expected Output:
A window with a text entry box and a button labeled "Get
Input." When the button is clicked, the entered text is
printed in the console.

4. Check Button Widget


Question: Write a Python program to create a check
button that toggles a selection.

import tkinter as tk
root = tk.Tk()
root.title("Check Button Example")
var = tk.IntVar()
check_button = tk.Checkbutton(root, text="Accept
Terms", variable=var)
check_button.pack()
def check_state():
print("Checked" if var.get() else "Unchecked")
button = tk.Button(root, text="Check State",
command=check_state)
button.pack()
root.mainloop()

Expected Output:
A window with a check button labeled "Accept Terms."
When the button "Check State" is clicked, the state
(Checked/Unchecked) is printed in the console.
5. Radio Button Widget
Question: Write a Python program to create radio buttons
for gender selection.

import tkinter as tk
root = tk.Tk()
root.title("Radio Button Example")
gender = tk.StringVar(value="None")
radio1 = tk.Radiobutton(root, text="Male",
variable=gender, value="Male")
radio2 = tk.Radiobutton(root, text="Female",
variable=gender, value="Female")
radio1.pack()
radio2.pack()
def show_gender():
print("Selected Gender:", gender.get())
button = tk.Button(root, text="Show Gender",
command=show_gender)
button.pack()
root.mainloop()

Expected Output:
A window with two radio buttons labeled "Male" and
"Female." When the "Show Gender" button is clicked, the
selected gender is printed in the console.

6. Listbox Widget
Question: Write a Python program to display a list of
options using Listbox.

import tkinter as tk
root = tk.Tk()
root.title("Listbox Example")
listbox = tk.Listbox(root)
options = ["Option 1", "Option 2", "Option 3"]
for option in options:
listbox.insert(tk.END, option)
listbox.pack()
def show_selection():
selection = listbox.get(tk.ACTIVE)
print("Selected:", selection)
button = tk.Button(root, text="Show Selection",
command=show_selection)
button.pack()
root.mainloop()

Expected Output:
A window with a list box displaying options. When
"Show Selection" is clicked, the selected option is printed
in the console.
7. Scrollbar Widget
Question: Write a Python program to create a scrollable
list using Listbox and Scrollbar.
import tkinter as tk
root = tk.Tk()
root.title("Scrollbar Example")
listbox = tk.Listbox(root)
scrollbar = tk.Scrollbar(root)

scrollbar.pack(side=tk.RIGHT, fill=tk.Y)
listbox.pack(side=tk.LEFT, fill=tk.BOTH)
listbox.config(yscrollcommand=scrollbar.set)
scrollbar.config(command=listbox.yview)
for i in range(50):
listbox.insert(tk.END, f"Item {i+1}")
root.mainloop()

Expected Output:
A window with a scrollable list of 50 items. The scrollbar
allows you to scroll through the list.

8. Menu Widget
Question: Write a Python program to create a menu bar
with File and Edit menus.
import tkinter as tk
root = tk.Tk()
root.title("Menu Example")
menu_bar = tk.Menu(root)
file_menu = tk.Menu(menu_bar, tearoff=0)
file_menu.add_command(label="New")
file_menu.add_command(label="Open")
file_menu.add_command(label="Exit",
command=root.quit)
menu_bar.add_cascade(label="File", menu=file_menu)
edit_menu = tk.Menu(menu_bar, tearoff=0)
edit_menu.add_command(label="Cut")
edit_menu.add_command(label="Copy")
edit_menu.add_command(label="Paste")
menu_bar.add_cascade(label="Edit", menu=edit_menu)
root.config(menu=menu_bar)
root.mainloop()

Expected Output:
A window with a menu bar having "File" and "Edit"
options. The "File" menu contains "New," "Open," and
"Exit," and the "Edit" menu contains "Cut," "Copy," and
"Paste."
9. Combobox Widget
Question: Write a Python program to create a Combobox
with options.
import tkinter as tk
from tkinter import ttk
root = tk.Tk()
root.title("Combobox Example")
combobox = ttk.Combobox(root, values=["Option 1",
"Option 2", "Option 3"])
combobox.pack()
def show_selected():
print("Selected:", combobox.get())
button = tk.Button(root, text="Show Selected",
command=show_selected)
button.pack()
root.mainloop()
Expected Output:
A window with a combobox showing "Option 1," "Option
2," and "Option 3." When "Show Selected" is clicked, the
selected option is printed in the console.

10. Message Widget


Question: Write a Python program to display a message
using the Message widget.
import tkinter as tk
root = tk.Tk()
root.title("Message Example")
message = tk.Message(root, text="This is a Message
widget example", width=200)
message.pack()
root.mainloop()
Expected Output:
A window with a message displayed: "This is a Message
widget example."

You might also like