DEV Community

Saurav Kumar
Saurav Kumar

Posted on

How I made an Instagram Profile Pic Downloader with Python and Tkinter

Disclaimer: This is only for educational purposes and please don’t misuse this by downloading a random person’s profile pic.

Hello Guys!

Today I will be sharing my code and the experience that I had while building this small project called “Instagram Profile Pic Downloader.”

By reading this blog you will be able to create the UI of the downloader using Tkinter.

First, let’s discuss some basic things that you need to know about Tkinter:

What is Tkinter?

  • Tkinter is the standard GUI library for Python.

  • Python when combined with Tkinter provides a fast and easy way to create GUI applications.

  • Tkinter provides a powerful object-oriented interface to the Tk GUI toolkit.

Let's Code

So let’s get started with the coding part and hope it will help you to understand Tkinter and NSIS tool.

So first we will import 2 modules: one is instaloader and another is tkinter.

Before that, you need to install instaloader module.

To do that just open your command prompt and run this command:
pip install instaloader or pip3 install instaloader

import instaloader
import tkinter

The Instaloader module is a Python package that has great functionalities to scrap instagram. It is used to download: Posts of public/private accounts, stories, and IGTV.

But here we will be using Instaloader to only download profile pictures of the account whether it is public/private.

Now we will create the canvas/window of the program.

root = tk.Tk()
root.title("profile Pic Downloader")
root.geometry("300x200")

The size of the window will be 300 x 200 and the title will be “Profile Pic Downloader”.

You can set the size and title according to yourself.

Now let's declare the variable and the function for downloading the profile picture.

user_var = tk.StringVar()
def download():
mod = instaloader.Instaloader()
mod.download_profile(user_entry.get(), profile_pic_only=True)
user_entry.delete(0, tk.END)

Okay, so user_var is the variable that will store the userName of the profile.

And in the download() function, In the first line we are loading the instaloader module. And then using the download_profile function of the instaloader module.

You can see that for the 2nd parameter of that function, we have written profile_pic_only = True, This tells that it will only download the profile picture.

Now we will create a label, text box, and button and place them in the window that we created above.

user_label = tk.Label(root, text = 'Enter Insta Id: ', font=('calibre', 10, 'bold'))
user_entry = tk.Entry(root, textvariable = user_var, font=('calibre',10,'normal'))
download_button = tk.Button(root, text = 'Download', command = download)
user_label.grid(row=0,column=0)
user_entry.grid(row=0,column=1)
download_button.grid(row=1,column=1)
root.mainloop()

user_label just holds the Label and user_entry is the text box where you will enter the user name of the profile which you want to download.

And the line below the button is the code for placing all the labels, text boxes, and buttons on the canvas. Here we have used grid() to place them in the window.

The last line is for holding the whole window until the cross button is pressed.

Below is the whole code for the project:

import instaloader
import tkinter as tk
root = tk.Tk()
root.title("profile Pic Downloader")
root.geometry("300x200")
user_var = tk.StringVar()
def download():
mod = instaloader.Instaloader()
mod.download_profile(user_entry.get(), profile_pic_only=True)
user_entry.delete(0, tk.END)
user_label = tk.Label(root, text = 'Enter Insta Id: ', font=('calibre', 10, 'bold'))
user_entry = tk.Entry(root, textvariable = user_var, font=('calibre',10,'normal'))
download_button = tk.Button(root, text = 'Download', command = download)
user_label.grid(row=0,column=0)
user_entry.grid(row=0,column=1)
download_button.grid(row=1,column=1)
root.mainloop()

Try it and if you like this article do leave a clap and if you face any difficulty in the code do comment and I will help you.

P S : This is my first ever blog/article, so if I have made mistakes please don’t mind and let me know, and I will correct it.

Thank you For Reading! And have a great Day!

Top comments (0)