PYTHON ASSIGNMENT
NAME:- TARUN
SRN :- PES1UG24CA160
QUESTION 1:-
CODE:-
import tkinter as tk
root= [Link]()
[Link]("Label Styling Excersise")
bold_label = [Link](root, text="Bold Text", font=("Bold", 12, "bold"))
bold_label.pack()
italic_label = [Link](root, text="Italic Text", font=("Helvetica", 12, "italic"))
italic_label.pack()
underline_label = [Link](root, text="Underline Text", font=("Helvetica", 12, "underline"))
underline_label.pack()
color_label = [Link](root, text="PES1UG24CA160", fg="blue", bg="yellow")
color_label.pack()
right_aligned_label = [Link](root, text="RIGHT ALIGNED", anchor="e", width=20)
right_aligned_label.pack()
aligned_label = [Link](root, text="Center Aligned", anchor="center")
aligned_label.pack()
border_label = [Link](root, text="With Border", relief="solid")
border_label.pack()
label = [Link](root, text="Padded Text", padx=10, pady=10)
[Link]()
[Link]()OUTPUT:-
QUESTION 2:-
CODE
import tkinter as tk
root = [Link]()
[Link]("Interactive Button States")
[Link]("300x300")
def toggle_button():
if button1['state'] == [Link]:
[Link](state=[Link], text="Disabled")
else:
[Link](state=[Link], text="Enabled")
def change_relief(relief_style):
[Link](relief=relief_style)
button1 = [Link](root, text="Enabled", bg="lightblue", fg="black",
activebackground="green", activeforeground="white",
relief="raised", padx=10, pady=5, state=[Link])
[Link](pady=20)
toggle_button_state = [Link](root, text="Toggle State", command=toggle_button)
toggle_button_state.pack(pady=10)
relief_styles = ["flat", "raised", "sunken", "groove", "ridge"]
for style in relief_styles:
button_style = [Link](root, text=[Link](), command=lambda s=style: change_relief(s))
button_style.pack(pady=5)
[Link]()
OUTPUT:-
QUESTION 3:-
import tkinter as tk
root = [Link]()
[Link]("25/10/24 - Experiencial learning Q3_")
counter = 0
def increment_counter():
global counter
counter += 1
counter_button.config(text=f"Count: {counter}_")
counter_button = [Link](root, text=f"Count: {counter}_", command=increment_counter)
counter_button.pack(pady=20)
[Link]()
OUTPUT:-
QUESTION 4:-
CODE:-
import tkinter as tk
def click_button(value):
current = [Link]()
[Link](0, [Link])
[Link]([Link], current + str(value))
def clear_entry():
[Link](0, [Link])
def calculate():
try:
result = eval([Link]())
[Link](0, [Link])
[Link]([Link], str(result))
except Exception as e:
[Link](0, [Link])
[Link]([Link], "Error")
root = [Link]()
[Link]("Calculator")
entry = [Link](root, width=16, font=('Arial', 24), justify='right')
[Link](row=0, column=0, columnspan=4)
buttons = [
'7', '8', '9', '/',
'4', '5', '6', '*',
'1', '2', '3', '-',
'0', '.', '=', '+'
row_val = 1
col_val = 0
for button in buttons:
if button == '=':
btn = [Link](root, text=button, command=calculate, width=5, height=2)
else:
btn = [Link](root, text=button, command=lambda b=button: click_button(b), width=5,
height=2)
[Link](row=row_val, column=col_val)
col_val += 1
if col_val > 3:
col_val = 0
row_val += 1
clear_btn = [Link](root, text='C', command=clear_entry, width=30, height=2)
clear_btn.grid(row=row_val, column=0, columnspan=4)
[Link]()
OUTPUT:-
QUESTION 5:-
CODE:-
import tkinter as tk
def change_label_text():
[Link](text="TEXT CHANGED!!")
root = [Link]()
[Link]("Change Label Text Example")
label = [Link](root, text="ORIGINAL TEXT")
[Link](pady=20)
button = [Link](root, text="Change Text", command=change_label_text)
[Link](pady=10)
[Link]()
OUTPUT:-