You are on page 1of 5

Practical 6

Program 1)

class Employee:
empCount = 0

def __init__(self, name, salary):


self.name = name
self.salary = salary
Employee.empCount+= 1

def displayCount(self):
print ("Total Employee %d" % Employee.empCount)

def displayEmployee(self):
print ("Name : ", self.name, ", Salary: ", self.salary)

emp1 = Employee("Zara", 2000)

emp2 = Employee("Manni", 5000)


emp1.displayEmployee()
emp2.displayEmployee()
print ("Total Employee %d" % Employee.empCount)

o/p
Name : Zara , Salary: 2000
Name : Manni , Salary: 5000
Total Employee 2

program 2

class st:
def __init__(self,n):
print ("hi",n)
v=st('college')

o/p hi college

program 3

class st:
def s1(self):
print ("base class")
class st1(st):
def s2(self):
print("derived class")

t=st1()
t.s1()
t.s2()

o/p
base class
derived class

program 4

class Calculation1:
def Summation(self,a,b):
return a+b;
class Calculation2:
def Multiplication(self,a,b):
return a*b;
class Derived(Calculation1,Calculation2):
def Divide(self,a,b):
return a/b;
d = Derived()
print(d.Summation(10,20))
print(d.Multiplication(10,20))
print(d.Divide(10,20))

o/p
30
200
0.5

PRACTICAL 7

Program 1

import tkinter
from tkinter import messagebox

top = tkinter.Tk()

def helloCallBack():

messagebox.showinfo( "Hello Python", "Hello World")

B = tkinter.Button(top, text ="Hello", command = helloCallBack)

B.pack()

top.mainloop()

When the above code is executed, it produces the following result −

Program 2

from tkinter import *

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

bottomframe = Frame(root)
bottomframe.pack( side = BOTTOM )

redbutton = Button(frame, text="Red", fg="red")


redbutton.pack( side = LEFT)

greenbutton = Button(frame, text="Brown", fg="brown")


greenbutton.pack( side = LEFT )

bluebutton = Button(frame, text="Blue", fg="blue")


bluebutton.pack( side = LEFT )

blackbutton = Button(bottomframe, text="Black", fg="black")


blackbutton.pack( side = BOTTOM)

root.mainloop()
When the above code is executed, it produces the following result −

Program 3

from tkinter import *

root = Tk()
var = StringVar()
label = Message( root, textvariable=var, relief=RAISED )

var.set("Hey!? How are you doing?")


label.pack()
root.mainloop()
When the above code is executed, it produces the following result −

Program 4)

import tkinter as tk

root = tk.Tk()

w = tk.Label(root, text="Red Sun", bg="red", fg="white")


w.pack()
w = tk.Label(root, text="Green Grass", bg="green", fg="black")
w.pack()
w = tk.Label(root, text="Blue Sky", bg="blue", fg="white")
w.pack()

tk.mainloop()

You might also like