Skip to content
Related Articles

Related Articles

Create a GUI to check Domain Availability using Tkinter
  • Last Updated : 29 Dec, 2020

There might be a case where a user wants to create a website and having certain ideas for the website’s name but is struck on their availability. So let’s develop a GUI that will check for domain availability. We will use the Python-whois module to get information about the website. It’s able to extract data for all the popular TLDs (com, org, net, …)

Installation

Before writing the code we need to install the python-whois Module. To install this type the below command in the terminal.

pip install python-whois

After installation, let write code with examples.

Import the python-whois module and extracting information from the site

Python3






import whois
  
  
whois.whois('geeksforgeeks.com')

Output:

If we are getting this type of information then it means this domain is registered for geeksforgeeks.

Now let’s write code for check domain availability.

Python3




# importing modules
import whois
import sys
  
# Use exception handle program
# and get information from whois
try:
    domain = whois.whois("geeksforgeeks.com")
    if domain.domain_name == None:
        sys.exit(1)
      
except :
    print("This domain is available")
else:
    print("Oops! this domain already purchased")

Output:

Oops! this domain already purchased by  GEEKSFORGEEKS.COM

Let’s check this on the domain site.



Checking myeeks.com domain availability.

Python3




domain = whois.whois("myeeks.com")

Output:

This domain is available

Let’s check this on the domain site.

Let’s create a GUI for the same using Tkinter.

Implementation:

Python3




# import modules
from tkinter import *
import whois
import sys
  
  
# user define funtion
# for get domain information
def Domain_info():
    try:
        domain = whois.whois(str(e1.get()))
          
        if domain.domain_name == None:
            sys.exit(1)
  
    except:
        result = "This domain is available"
      
    else:
        result = "Oops! this domain already purchased"
    res.set(result)
  
  
# object of tkinter
# and background set for red
master = Tk()
master.configure(bg='red')
  
# Variable Classes in tkinter
res = StringVar()
  
# Creating label for each information
# name using widget Label
Label(master, text="Website URL : ", bg="red").grid(row=0, sticky=W)
Label(master, text="Result :", bg="red").grid(row=3, sticky=W)
  
# Creating lebel for class variable
# name using widget Entry
Label(master, text="", textvariable=res, bg="red").grid(
    row=3, column=1, sticky=W)
  
e1 = Entry(master)
e1.grid(row=0, column=1)
  
# creating a button using the widget
# Button that will call the submit function
b = Button(master, text="Show", command=Domain_info, bg="Blue")
b.grid(row=0, column=2, columnspan=2, rowspan=2, padx=5, pady=5,)
  
mainloop()

Output:

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :