Create a GUI to check domain availability using Tkinter


What is the need for domain?

The internet has become a vital part of our daily lives. When it comes to businesses, having an online presence is crucial. Choosing the right domain name is the first step in establishing an online presence for any business. However, finding an available domain name can be a daunting task. In this technical document, we will guide you through the process of creating a graphical user interface (GUI) in Python using the Tkinter module to check domain name availability.

What is a domain and what are its components?

In the context of the internet, a domain name or simply a domain refers to the unique name that identifies a website or a web server on the World Wide Web. It is a part of a larger system called the Domain Name System (DNS) that helps in translating user-friendly domain names into IP addresses that computers use to identify each other on the internet.

A domain name consists of two or more components separated by periods. The rightmost component is known as the top-level domain (TLD) and usually identifies the type of organization or country associated with the domain. For example, .com is a common TLD that is used for commercial websites, while .org is used for non-profit organizations.

The next component to the left of the TLD is the second-level domain (SLD), which identifies the specific organization or entity associated with the domain. For example, in the domain name "google.com", "google" is the SLD and ".com" is the TLD.

Domains are used for various purposes such as identifying websites, email servers, and other resources on the internet. When someone types a domain name into their web browser, the browser sends a request to a DNS server to obtain the IP address associated with the domain. Once the IP address is obtained, the browser can then connect to the web server associated with the domain and retrieve the requested web page.

Domains are registered and managed by domain name registrars, which are companies authorized by the Internet Corporation for Assigned Names and Numbers (ICANN) to manage domain registrations. Registrars charge a fee for registering and renewing domain names, and they are responsible for maintaining the DNS records associated with each domain.

In summary, a domain name is a unique name that identifies a website or web server on the internet. It consists of two or more components separated by periods, and it is used to translate user-friendly domain names into IP addresses that computers can use to connect to web servers. Domains are registered and managed by domain name registrars, which are authorized by ICANN to manage domain registrations.

Prerequisites

Before we dive into the details of creating a GUI, you should have a basic understanding of Python programming, object-oriented programming (OOP) concepts, and how to work with the Tkinter module.

List of recommended settings −

  • pip install tkinter

  • It is expected that the user will have access to any standalone IDE such as VS-Code, PyCharm, Atom or Sublime text.

  • Even online Python compilers can also be used such as Kaggle.com, Google Cloud platform or any other will do.

  • Updated version of Python. At the time of writing the article I have used 3.10.9 version.

  • Knowledge of the use of Jupyter notebook.

  • Knowledge and application of virtual environment would be beneficial but not required.

  • It is also expected that the person will have a good understanding of statistics and mathematics.

Steps required to accomplish the task

Step 1: Import the necessary modules

import tkinter as tk
import requests

The Tkinter module is used to create the GUI window, and the requests module is used to make HTTP requests to the domain name registrar API.

Step 2: Create the GUI Window

root = tk.Tk()
root.title("Domain Availability Checker") 

Next, we need to create the GUI window. We can do this by creating an instance of the Tk() class from the Tkinter module. We can also set the title of the window using the title() method.

Step 3: Create Labels and Entry Fields

heading_label = tk.Label(root, text="Check Domain Availability", font=("Helvetica", 20, "bold"))
heading_label.grid(row=0, column=0, columnspan=2, padx=10, pady=10)

domain_label = tk.Label(root, text="Domain Name:")
domain_label.grid(row=1, column=0, padx=10, pady=10)

domain_entry = tk.Entry(root)
domain_entry.grid(row=1, column=1, padx=10, pady=10)

We will create two labels and two entry fields. The first label will display "Domain Name," and the second label will display the result of the domain name check. The first entry field will allow users to enter the domain name they want to check, and the second entry field will display the result. We used the grid() method to position the labels and entry fields in the GUI window.

Step 4: Create the Function to Check Domain Availability

Next, we will create a function to check the availability of the domain name. The function will be called when the user clicks the "Check" button.

def check_domain_availability():
   domain_name = domain_entry.get()

   try:
      whois.whois(domain_name)
      availability_label.config(text="Domain is not available")
   except:
      availability_label.config(text="Domain is available") 

Next, we define the function check_domain_availability(). This function will be called when the user clicks on the "Check Availability" button. The function takes the user input from the entry field and checks if the domain is available using the whois package. We first import the whois package, and then define a try-except block to handle the case where the domain is not available. If the domain is available, we display a message saying "Domain is available", and if it is not available, we display a message saying "Domain is not available".

Step 5: Create the check button

check_button = tk.Button(root, text="Check Availability", command=check_domain_availability)
check_button.grid(row=1, column=1, pady=10)

availability_label = tk.Label(root, text="")
availability_label.grid(row=2, column=0, columnspan=2) 

Finally, we create the button and label widgets and position them on the GUI window. We create a "Check Availability" button using the Button() function and assign the check_domain_availability() function to the command parameter. We also create a label widget to display the availability status using the Label() function. We then use the grid() method to position the widgets on the GUI window.

Step 6: Finally, we call the mainloop() function to run the GUI window.

root.mainloop() 

Final code, program

import tkinter as tk
import whois

root = tk.Tk()
root.title("Domain Availability Checker")

heading_label = tk.Label(root, text="Check Domain Availability", font=("Helvetica", 20, "bold"))
heading_label.grid(row=0, column=0, columnspan=2, padx=10, pady=10)

domain_label = tk.Label(root, text="Domain Name:")
domain_label.grid(row=1, column=0, padx=10, pady=10)

domain_entry = tk.Entry(root)
domain_entry.grid(row=1, column=1, padx=10, pady=10)

def check_domain_availability():
   domain_name = domain_entry.get()

   try:
      whois.whois(domain_name)
      availability_label.config(text="Domain is not available")
   except:
      availability_label.config(text="Domain is available")

check_button = tk.Button(root, text="Check Availability", command=check_domain_availability)
check_button.grid(row=2, column=1, pady=10)

availability_label = tk.Label(root, text="")
availability_label.grid(row=3, column=0, columnspan=2)

root.mainloop() 

When you run the code, you should see a GUI window with a heading, a label and an entry field to enter the domain name, a "Check Availability" button, and a label to display the availability status. When you enter a domain name and click on the button, the availability status will be displayed in the label widget.

Output

Step 1: The GUI opens up to ask for user input

Step 2: After the user inputs the query we can see the result

This picture shows user input and output of the domain availability checker.

Conclusion

In this article, we have discussed how to build a Domain Availability Checker Tool with a Graphical User Interface (GUI) using Tkinter. We have covered the steps involved in setting up the development environment, designing the GUI, writing the code, adding error handling, testing, and deployment. The Domain Availability Checker Tool can be a useful tool for businesses to check the availability of their desired domain name, and we hope this tutorial has been helpful in designing and building one.

Updated on: 20-Apr-2023

138 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements