You are on page 1of 8

Name:- Raunak Malkani Date:- 30/08/2021

UID:- 20BIT032

Practical 5: Modules

D. Aim: Open a new file in IDLE (“New Window” in the “File” menu)
and save it as geometry.py in the directory where you keep the files
you create for this course. Then copy the functions you wrote for
calculating volumes and areas in the “Control Flow and Functions”
exercise into this file and save it. Now open a new file and save it in
the same directory. You should now be able to import your own
module like this:import geometry Try and add print dir(geometry) to
the file and run it.Now write a function pointyShapeVolume(x, y,
squareBase) that calculates the volume of a square pyramid if
squareBase is True and of a right circular cone if squareBase is False.
x is the length of an edge on a square if squareBase is True and the
radius of a circle when squareBase is False. y is the height of the
object.First use squareBase to distinguish the cases. Use the
circleArea and squareArea from the geometry module to calculate
the base areas.

Code:
Module.py
import geometry

print(dir(geometry))

def pointyShapeVolume(x,y,squareBase):
if squareBase:
base=geometry.squareArea(x)*(y/3)
return base
else:
base=geometry.circleArea(x)*(y/3)
return base

print(pointyShapeVolume(4,5,True))
print(pointyShapeVolume(4,5,False))

Geometry.py
import math
def circleArea(r):
return math.pi*r*r

def squareArea(a):
return a**2

Output:-
Practical 6: GUI Programming: (using Tkinter/wxPython/PyQt)

A. Aim: i. Try to configure the widget with various options like:


bg=”red”, family=”times”, size=18. ii. Create the following GUI
form
Code:

from tkinter import *

window = Tk() #window to appear

window.title("First GUI") #title for the window

window.geometry("600x600")

lb1 = Label(window, text = "Hello Nivedita", bg = "black",fg =


"white", font = ("Georgia",18), width = 50).pack()

print("\n")

lb2 = Label(window, text = "Red Text in Times Font",fg = "red", font


= ("Times New Roman",18), width = 50).pack()

lb3 = Label(window, text = "Green Text in Helvetica Font", bg =


"dark green",fg = "SeaGreen1", font = ("Helvetica",18), width =
50).pack()

lb4 = Label(window, text = "Blue Text in Verdana Bold", bg =


"yellow", fg = "blue", font = ("Times New Roman",18, "bold"),
width = 25).pack()

window.mainloop() #keeps window running until closed explicitly

Output:-
B. Aim: Try to change the widget type and configuration options
to experiment with other widget types like Message, Button,
Entry, Checkbutton, Radiobutton, Scale etc.

1. Buttons: a)

Code:

from tkinter import *

def result():
print("The sum is:",2+4)

root=Tk()
win=Frame(root)
win.pack()

Label(win,text="click ADD to get the sum or Quit to


exit").pack(side=TOP)

Button(win,text="ADD",bg="#80ff80",fg="#4d4d00",command=res
ult).pack(side=LEFT)
Button(win,text="QUIT",bg="red",fg="yellow",command=quit).pac
k(side=RIGHT)
root.mainloop()

Output:-

b) Create the following GUI Form using tkinter that prints “Hello,
your_name! You clicked the button” on IDLE if you click on button
“Click Me” and shuts down the window if you click on “Quit”.
Code:
from tkinter import *

root = Tk()

root.geometry('250x100')

def onClick():

print("Hello, Nivedita! You clicked the button")

Button(root, text = "Quit!", fg = "red", font = ('calibri', 10, 'bold',


'underline'), width = 10, command = quit).pack()

Label(root, text = "").pack()

Button(root, text = "Click me!", command = onClick()).pack()

root.mainloop()

Output:-

c) Create the following GUI Form using tkinter that prints “You
clicked the download button” on IDLE if you click on the button.
Code:
import tkinter as tk

from tkinter import ttk

root = tk.Tk()

root.geometry('300x150')

root.title('Image Button Demo')

def download_clicked():

print("You clicked the download button")

download_icon = tk.PhotoImage(file=
'D:\SEM_3\Practicals\APP\Prac_6\download1.png')

download_button = ttk.Button(root, image = download_icon,


text = 'Download', compound = tk.LEFT, command =
download_clicked)

download_button.pack(ipadx = 5, ipady = 5,expand = True)

root.mainloop()

Output:-

You might also like