Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Create a GUI to check domain availability using Tkinter
Building a domain availability checker with a GUI helps businesses quickly verify if their desired domain names are available. We'll create this tool using Python's Tkinter for the interface and the python-whois library for domain checking.
What is a Domain?
A domain name is a unique identifier for websites on the internet. It consists of two main parts: the second-level domain (like "google") and the top-level domain or TLD (like ".com"). The Domain Name System (DNS) translates these human-readable names into IP addresses that computers use to locate web servers.
Common TLD examples include .com for commercial sites, .org for organizations, and .edu for educational institutions.
Prerequisites
Before creating the GUI, ensure you have ?
- Python 3.6 or higher installed
- Basic understanding of Python and Tkinter
- Required packages:
pip install python-whois
Creating the Domain Checker GUI
Step 1: Import Required Modules
import tkinter as tk from tkinter import messagebox import whois
We import tkinter for GUI creation, messagebox for error handling, and whois for domain availability checking.
Step 2: Create the Main Window
root = tk.Tk()
root.title("Domain Availability Checker")
root.geometry("400x300")
root.resizable(False, False)
Step 3: Add GUI Components
# Heading
heading_label = tk.Label(root, text="Check Domain Availability",
font=("Helvetica", 16, "bold"))
heading_label.grid(row=0, column=0, columnspan=2, padx=10, pady=20)
# Domain input
domain_label = tk.Label(root, text="Domain Name:")
domain_label.grid(row=1, column=0, padx=10, pady=10, sticky="e")
domain_entry = tk.Entry(root, width=25, font=("Arial", 11))
domain_entry.grid(row=1, column=1, padx=10, pady=10)
Step 4: Create Domain Check Function
def check_domain_availability():
domain_name = domain_entry.get().strip()
if not domain_name:
availability_label.config(text="Please enter a domain name", fg="red")
return
# Add .com if no TLD specified
if '.' not in domain_name:
domain_name += '.com'
availability_label.config(text="Checking...", fg="blue")
root.update()
try:
domain_info = whois.whois(domain_name)
# Check if domain is registered
if domain_info.domain_name:
availability_label.config(text=f"{domain_name} is NOT available", fg="red")
else:
availability_label.config(text=f"{domain_name} is available", fg="green")
except Exception:
availability_label.config(text=f"{domain_name} is available", fg="green")
Step 5: Add Button and Result Label
# Check button
check_button = tk.Button(root, text="Check Availability",
command=check_domain_availability,
bg="#4CAF50", fg="white", font=("Arial", 11, "bold"),
padx=20, pady=5)
check_button.grid(row=2, column=0, columnspan=2, pady=20)
# Result label
availability_label = tk.Label(root, text="", font=("Arial", 12, "bold"))
availability_label.grid(row=3, column=0, columnspan=2, pady=10)
Step 6: Start the Application
# Center the window
root.update_idletasks()
width = root.winfo_width()
height = root.winfo_height()
x = (root.winfo_screenwidth() // 2) - (width // 2)
y = (root.winfo_screenheight() // 2) - (height // 2)
root.geometry(f'{width}x{height}+{x}+{y}')
root.mainloop()
Complete Code
import tkinter as tk
from tkinter import messagebox
import whois
def check_domain_availability():
domain_name = domain_entry.get().strip()
if not domain_name:
availability_label.config(text="Please enter a domain name", fg="red")
return
# Add .com if no TLD specified
if '.' not in domain_name:
domain_name += '.com'
availability_label.config(text="Checking...", fg="blue")
root.update()
try:
domain_info = whois.whois(domain_name)
# Check if domain is registered
if domain_info.domain_name:
availability_label.config(text=f"{domain_name} is NOT available", fg="red")
else:
availability_label.config(text=f"{domain_name} is available", fg="green")
except Exception:
availability_label.config(text=f"{domain_name} is available", fg="green")
# Create main window
root = tk.Tk()
root.title("Domain Availability Checker")
root.geometry("400x300")
root.resizable(False, False)
# GUI Components
heading_label = tk.Label(root, text="Check Domain Availability",
font=("Helvetica", 16, "bold"))
heading_label.grid(row=0, column=0, columnspan=2, padx=10, pady=20)
domain_label = tk.Label(root, text="Domain Name:")
domain_label.grid(row=1, column=0, padx=10, pady=10, sticky="e")
domain_entry = tk.Entry(root, width=25, font=("Arial", 11))
domain_entry.grid(row=1, column=1, padx=10, pady=10)
check_button = tk.Button(root, text="Check Availability",
command=check_domain_availability,
bg="#4CAF50", fg="white", font=("Arial", 11, "bold"),
padx=20, pady=5)
check_button.grid(row=2, column=0, columnspan=2, pady=20)
availability_label = tk.Label(root, text="", font=("Arial", 12, "bold"))
availability_label.grid(row=3, column=0, columnspan=2, pady=10)
# Center the window
root.update_idletasks()
width = root.winfo_width()
height = root.winfo_height()
x = (root.winfo_screenwidth() // 2) - (width // 2)
y = (root.winfo_screenheight() // 2) - (height // 2)
root.geometry(f'{width}x{height}+{x}+{y}')
root.mainloop()
Key Features
- Input validation ? Checks for empty input fields
- Auto TLD addition ? Adds .com if no extension is provided
- Visual feedback ? Color-coded results (green for available, red for taken)
- Centered window ? Automatically centers the GUI on screen
- Loading indicator ? Shows "Checking..." while processing
How It Works
The application uses the python-whois library to query domain registration databases. When a domain is registered, the WHOIS service returns registration information. If an exception occurs (typically for unregistered domains), we assume the domain is available.
Conclusion
This domain availability checker provides a simple GUI interface for businesses to verify domain names quickly. The tool combines Tkinter's user-friendly interface with WHOIS database queries to deliver real-time domain availability information.
---