3 Interesting Python Projects With Code For Beginners!

Share on facebook
Share on twitter
Share on linkedin
Share on telegram
Share on whatsapp

Contents

Beginners when they start programming often get bored if they don't have a chance to play around with some interesting code. Then, in this article, I have explained three Python projects with Code. Beginning programmers can try implementing these projects and get their hands dirty with the Python language.

Let's start with the first.

1. QR code generation using Python

QR code stands for Quick Response Code. QR codes may seem simple but they are capable of storing large amounts of data. Regardless of the amount of data they contain, scanned QR code allows user to access information instantly. This is why they are called Quick Response Code.

These are being used in many scenarios these days. It first appeared in Japan in 1994. QR codes can be used to store (encode) a lot of data and also of various kinds. For instance, can be used to encode:

  1. Contact details
  2. ID de Facebook, ID de Instagram, ID de Twitter, WhatsApp ID and more.
  3. Event details
  4. Youtube links
  5. Product details
  6. Direct link to download an application on the Apple App Store or Google Play.
  7. They are also used to carry out digital transactions simply by scanning QR codes.
  8. Access Wi-Fi by storing encryption details like SSID, password and encryption type.

This list goes on….!

88997qr-code-still-trending-in-2020-5533203

Image source: https://www.assetinfinity.com/

We have just seen some advantages of QR codes. Now we will learn here how we can generate QR codes in Python.

For generating QR codes using Python, we will use a Python module called QR code.

Link: https://pypi.org/project/qrcode/

Install it using this command: pip instalar qrcode

We will generate a QR code to encode the youtube link and also explore more. Generating QR codes is simple. Just pass the text, the link or any content to 'do’ QRcode module function.

import qrcode
img = qrcode.make("https://www.youtube.com/")
img.save("youtubeQR.jpg")

When running this code, the output is:

34772qr1-7173933

You can scan it and verify it.

You can see that they are just 3 lines of code to generate this QR Code. One more thing to mention is that you don't need to always have to give a link to the qrcode.make function (). You can also provide simple text.

For instance:

Can encode: India is a country with many religions. I love india.

Probemoslo:

import qrcode
img = qrcode.make("India is a country with many religions. I love India.")
img.save("youtubeQR.jpg")

The exit QR code for this text is:

88764qr2-9215380

Scan it from your mobile and you will get the content.

So this is the only part, which involves generating a QR code and scanning it. But, What if we want to read this QR Code, namely, now we want to know what was encoded in the QR Code without scanning it? For this we will use OpenCV. OpenCV is a library of scheduling functions focused on real-time computer vision tasks.

Instalar opencv: pip instalar opencv-python

Code to decode a QR code to rediscover the original string.

import cv2
d = cv2.QRCodeDetector()
val, _, _ = d.detectAndDecode(cv2.imread("myQRCode.jpg"))
print("Decoded text is: ", val)

Production:

India is a country with many religions. I love India.

This QRcode module in Python provides many other functionalities. Go and try them yourself by reading the documentation. It will be fun and amazing for you.

2. GUI application for Calendar with Python using Tkinter

In Python, we can create GUI using Tkinter. If you are very imaginative and creative, you can do amazing things with Tkinter. Here, we will create a Python Calendar GUI application using Tkinter. In this app, the user must enter the year for which they want to see the calendar, and then the calendar will appear.

Install Tkinter first using this command: pip instalar tk

We would also need a Calendar pack, but we don't have to install it. It is a default package that comes automatically with python.

Program:

#import calendar module
import calendar
#import tkinter module
from tkinter import *
#This function displays calendar for a given year
def showCalender():
    gui = Tk()
    gui.config(background='grey')
    gui.title("Calender for the year")
    gui.geometry("550x600")
    year = int(year_field.get())
    gui_content= calendar.calendar(year)
    calYear = Label(gui, text= gui_content, font= "Consoles 10 bold")
    calYear.grid(row=5, column=1,padx=20)
    gui.mainloop()

Explanation

The ShowCalender function displays the calendar. Enter a year in the search box and when Enter is pressed, here you manage how the calendar should be displayed. You set the background color which is gray here and it can be changed in the code according to your needs. It also sets the dimension of the calendar which is 550 × 600 here. Then request the year of entry as a whole number. Once the user enters the year, the content of the calendar is obtained from the Python calendar module passing the year as an argument.

#Driver code
if __name__=='__main__':
    new = Tk()
    new.config(background='grey')
    new.title("Calender")
    new.geometry("250x140")
    cal = Label(new, text="Calender",bg='grey',font=("times", 28, "bold"))
    #Label for enter year
    year = Label(new, text="Enter year", bg='dark grey')
    #text box for year input
    year_field=Entry(new)
    button = Button(new, text="Show Calender",fg='Black',bg='Blue',command=showCalender)
    #adjusting widgets in position
    cal.grid(row=1, column=1)
    year.grid(row=2, column=1)
    year_field.grid(row=3, column=1)
    button.grid(row=4, column=1)
    Exit.grid(row=6, column=1)
    new.mainloop()

Explanation

In controller code, first of all we give the background color to the left side of the screen (as shown in the picture below). Since it is a small window to give the year of entry, we establish its dimension in 250 × 140. In the button line below year_field, we call the showCalendar function we did above. This function shows us the complete calendar for an input year.

Now, we also need to adjust the widgets in the calendar, for that we define the location on the grid for everything. You can play around by changing the row and column parameters of the grid to explore further.

Production:

21950c2-6934915

3. Convert Image to Pencil Sketch Using Python

This will be interesting. We will write the code step by step with the explanation.

We will use the OpenCV library for this project. Install it using pip instalar opencv-python command.

Paso 1: Find an image that you want to convert to a pencil drawing.

We will use a dog image. You can choose what you want.

Paso 2: Read the image in RBG format and then convert it to a grayscale image. Now, the image becomes a classic black and white photo.

import cv2
#reading image
image = cv2.imread("dog.jpg")
#converting BGR image to grayscale
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

Paso 3: Invert the grayscale image also called a negative image, this will be our inverted grayscale image. The investment is basically used to improve the details.

#image inversion
inverted_image = 255 - gray_image

Paso 4: Finally create the pencil sketch by blending the grayscale image with the inverted blur image. This is done by dividing the grayscale image by the inverted blur image.

blurred = cv2.GaussianBlur(inverted_image, (21, 21), 0)
inverted_blurred = 255 - blurred
pencil_sketch = cv2.divide(gray_image, inverted_blurred, scale=256.0)

Now we have our pencil_sketch. Then, show it using OpenCV.

cv2.imshow("Original Image", image)
cv2.imshow("Pencil Sketch of Dog", pencil_sketch)
cv2.waitKey(0)

Production:

92705d-3177258

Look, how beautiful it is. Then, just try this with other images too and play with python. These are just 3 projects we discuss. You can try more projects that will interest you in programming. Then, here is the list of some projects.

List of some more Python projects to try:

1. Weight converter with GUI using Tkinter

2. Send custom emails with Python

3. Unique GUI of password generator

4. Text to speech with Python

5. Twitter data extraction

6. Juego de Python Rock Paper Scissors

7. Alarm clock with GUI

8. Youtube video downloader

9. Python website blocker

10. Python game

Final notes:

Python is a very easy language to learn due to its simple syntax. Here we discuss only basic Python projects. Hope this article is helpful to you. Let's connect Linkedin.

Thanks for reading if you got here :).

The media shown in this article is not the property of Analytics Vidhya and is used at the author's discretion.

Subscribe to our Newsletter

We will not send you SPAM mail. We hate it as much as you.