Lab 9
Lab 9
Experiment- 9
CODE:
import numpy as np
import matplotlib.pyplot as plt
data = {'C':21, 'C++':15, 'Java':30, 'Python':39}
courses = list(data.keys())
values = list(data.values())
fig = plt.figure(figsize = (9, 5))
plt.bar(courses, values, color ='maroon', width = 0.3)
plt.xlabel("Courses offered")
plt.ylabel("No. of students enrolled")
plt.title("Students enrolled in different courses")
plt.show()
OUTPUT:
Branch: EC/EL/ICT Enrollment no: IU2241240033
CODE:
from matplotlib import pyplot as plt
import numpy as np
cars = ['McLaren', 'BMW', 'Ferrari','Rolls Royace', 'Aston Martin', 'Porche']
mycolors = ["black", "hotpink", "b", "#4CAF50","orange","maroon"]
data = [23, 17, 35, 29, 12, 41]
fig = plt.figure(figsize=(10, 7))
plt.pie(data, labels=cars, colors = mycolors)
plt.show()
OUTPUT:
Branch: EC/EL/ICT Enrollment no: IU2241240033
3) Write a tkinter code to Create a dropdown list to select a city from the given list of cities.
CODE:
import tkinter as tk
from tkinter import ttk
OUTPUT:
CODE:
import tkinter as tk
from tkinter import PhotoImage
root = tk.Tk()
root.title("Image Display")
Branch: EC/EL/ICT Enrollment no: IU2241240033
image_path = "sampleimg.png"
try:
img = PhotoImage(file=image_path)
except tk.TclError:
print(f"Error loading image from {image_path}")
img = None
image_label = tk.Label(root, image=img)
image_label.pack()
root.mainloop()
OUTPUT:
Branch: EC/EL/ICT Enrollment no: IU2241240033
CODE:
import tkinter as tk
from tkinter import messagebox
def register_user():
username = entry_username.get()
password = entry_password.get()
messagebox.showinfo("Registration Successful", f"Welcome, {username}!")
root = tk.Tk()
root.title("User Registration")
label_username = tk.Label(root, text="Username:")
label_password = tk.Label(root, text="Password:")
entry_username = tk.Entry(root)
entry_password = tk.Entry(root, show="*") # Mask the password
register_button = tk.Button(root, text="Register", command=register_user)
label_username.pack()
entry_username.pack()
label_password.pack()
entry_password.pack()
register_button.pack()
root.mainloop()
OUTPUT:
Branch: EC/EL/ICT Enrollment no: IU2241240033
CODE:
import turtle
screen = turtle.Screen()
screen.bgcolor("white") # Background color
artist = turtle.Turtle()
artist.penup()
artist.goto(-50, -50) # Position the turtle
artist.pendown()
artist.color("red") # Square color
for _ in range(4):
artist.forward(100) # Move forward
artist.right(90) # Turn right
artist.penup()
artist.goto(0, 50) # Position for the star
artist.pendown()
artist.color("blue") # Star color
for _ in range(5):
artist.forward(100) # Move forward
artist.right(144) # Turn right
artist.hideturtle()
turtle.done()
OUTPUT: