Create a GUI to check Domain Availability using Tkinter

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



filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


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

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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")

chevron_right


Output:

Oops! this domain already purchased by  GEEKSFORGEEKS.COM

Let’s check this on the domain site.



Checking myeeks.com domain availability.

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


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

filter_none

edit
close

play_arrow

link
brightness_4
code

# 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()

chevron_right


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.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.