0% found this document useful (0 votes)
2 views3 pages

6 Exp Python

The document outlines Experiment No. 6 for the Department of Computer Science and Engineering at Mahatma Gandhi Mission's College, focusing on Python programming for file handling and GUI. It includes three specific tasks: finding the most frequent words in a text file, performing file operations using pickle, and designing a graphical user interface with Tkinter. The conclusion states that basic Python programs were successfully implemented to demonstrate these concepts.

Uploaded by

shubham
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)
2 views3 pages

6 Exp Python

The document outlines Experiment No. 6 for the Department of Computer Science and Engineering at Mahatma Gandhi Mission's College, focusing on Python programming for file handling and GUI. It includes three specific tasks: finding the most frequent words in a text file, performing file operations using pickle, and designing a graphical user interface with Tkinter. The conclusion states that basic Python programs were successfully implemented to demonstrate these concepts.

Uploaded by

shubham
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/ 3

Mahatma Gandhi Mission's College of Engineering and Technology

Department of Computer Science and Engineering (AIML &DS)

Academic Year 2024-25(Even Sem)

Experiment No. 6

Name of Student Shyamdin Prajapati

Roll No 55

DOP DOS Marks/Grade Signature

Aim: Write python programs to understand File handling and GUI.


Objective:

∙ To study File handling and GUI.


Outcome: Students will be able to write python programs on File handling and GUI.

i) WAP to find the most frequent words in a text read from a file.
Source Code:

from collections import Counter


import re

def find_most_frequent_words(file_path):
with open("a1.txt", 'r') as file:
text = file.read().lower()
words = re.findall(r'\b\w+\b', text)
word_count = Counter(words)
for word, count in word_count.most_common(10):
print(f"{word}: {count}")
file_path = "a1.txt"
find_most_frequent_words(file_path)

Input and Output:

LAB MANUAL [IV --- Python Lab] Page 20


Mahatma Gandhi Mission's College of Engineering and Technology

Department of Computer Science and Engineering (AIML &DS)

Academic Year 2024-25(Even Sem)

ii) WAP to understand different file handling operations with pickle.


Source Code:

import pickle

def write_to_file(filename, data):


with open(filename, 'wb') as file:
pickle.dump(data, file)
print(f"Data has been written to {filename}")

def read_from_file(filename):
with open(filename, 'rb') as file:
data = pickle.load(file)
return data

data = {
'name': 'Ashish prajapati',
'age': 23,
'city': 'Thane'
}

filename = 'data.pkl'
write_to_file(filename, data)
loaded_data = read_from_file(filename)
print("\nLoaded data:")
print(loaded_data)

Input and Output:

LAB MANUAL [IV --- Python Lab] Page 21


Mahatma Gandhi Mission's College of Engineering and Technology

Department of Computer Science and Engineering (AIML &DS)

Academic Year 2024-25(Even Sem)


iii) WAP to design Graphical user interface (GUI) using built-in tools in python (Tkinter,
PyQt,Kivy etc.).
Source Code:
import tkinter as tk
class SmileyCanvas(tk.Canvas):
def __init__(self, parent):
super().__init__(parent)
self.create_smiley()

def create_smiley(self):
self.create_oval(50, 50, 250, 250, fill="yellow", outline="yellow")
self.create_oval(100, 100, 130, 130, fill="black", outline="black")
self.create_oval(170, 100, 200, 130, fill="black", outline="black")
self.create_arc(100, 130, 200, 190, start=0, extent=-180, fill="black", style=tk.ARC)

if __name__ == "__main__":
root = tk.Tk()
root.title("Smiley Face")
smiley_canvas = SmileyCanvas(root)
smiley_canvas.pack(fill="both", expand=True)
root.geometry("300x300")
root.mainloop()

Input and Output:

Conclusion: We successfully implement basic python programs to demonstrate File handling and
GUI using Tkinter.

LAB MANUAL [IV --- Python Lab] Page 22

You might also like