Create a GUI to Get Domain Information using Tkinter

In today's digital world, businesses rely heavily on their online presence. Before setting up a website or purchasing a domain name, it's essential to gather comprehensive information about the domain you plan to use. This includes details like domain owner, server location, IP address, and WHOIS records. In this tutorial, we'll create a GUI application using Python's Tkinter to retrieve domain information.

What is GUI?

GUI (Graphical User Interface) presents data to users through interactive windows, buttons, and menus instead of traditional command-line interfaces. It allows users to interact with computers more comfortably and intuitively using visual elements rather than text commands.

Why Use Tkinter for GUI?

Tkinter is Python's built-in GUI library, making it the most accessible choice for creating graphical applications. Since it's included with Python, no additional installations are required. It provides comprehensive tools for building GUIs, including widgets, menu bars, and canvas objects.

Key Advantages of Tkinter

  • Built-in with Python ? No need to install additional libraries

  • Cross-platform compatibility ? Works on Windows, macOS, and Linux

  • Easy to learn ? Simple and intuitive API for beginners

  • Customizable widgets ? Wide range of configurable components

  • Flexible layouts ? Multiple geometry managers (pack, grid, place)

  • Event-driven programming ? Responds to user interactions naturally

Prerequisites

Before starting, ensure you have:

  • Basic Python programming knowledge

  • Understanding of object-oriented programming concepts

  • Python 3.x installed on your system

  • Install required package: pip install python-whois

Creating the Domain Information GUI

Step 1: Import Required Libraries

First, import the necessary libraries for our GUI application ?

from tkinter import *
import whois
import socket

We import tkinter for the GUI, whois for domain registration information, and socket for DNS lookups.

Step 2: Create the Main Application Class

Let's create a complete working example of our domain information GUI ?

from tkinter import *
import whois
import socket
from tkinter import messagebox

class DomainInfoGUI:
    def __init__(self):
        self.window = Tk()
        self.window.geometry("600x500")
        self.window.title("Domain Information Tool")
        self.window.configure(bg='lightblue')
        
        # Create main frame
        main_frame = Frame(self.window, bg='lightblue')
        main_frame.pack(pady=20)
        
        # Domain input section
        Label(main_frame, text="Enter Domain Name:", font=('Arial', 12, 'bold'), bg='lightblue').pack(pady=10)
        
        self.entry_domain = Entry(main_frame, width=40, font=('Arial', 11))
        self.entry_domain.pack(pady=5)
        
        # Buttons frame
        buttons_frame = Frame(main_frame, bg='lightblue')
        buttons_frame.pack(pady=15)
        
        Button(buttons_frame, text="Get WHOIS Info", command=self.get_whois_info, 
               bg='green', fg='white', font=('Arial', 10)).pack(side=LEFT, padx=5)
        Button(buttons_frame, text="Get DNS Info", command=self.get_dns_info,
               bg='blue', fg='white', font=('Arial', 10)).pack(side=LEFT, padx=5)
        Button(buttons_frame, text="Clear All", command=self.clear_all,
               bg='red', fg='white', font=('Arial', 10)).pack(side=LEFT, padx=5)
        
        # Results frame
        self.results_frame = Frame(self.window, bg='lightblue')
        self.results_frame.pack(pady=10, fill=BOTH, expand=True)
        
    def get_whois_info(self):
        domain_name = self.entry_domain.get().strip()
        if not domain_name:
            messagebox.showwarning("Input Error", "Please enter a domain name!")
            return
            
        try:
            self.clear_results()
            w = whois.whois(domain_name)
            
            Label(self.results_frame, text=f"WHOIS Information for {domain_name}:", 
                  font=('Arial', 12, 'bold'), bg='lightblue').pack(pady=10)
            
            text_widget = Text(self.results_frame, height=15, width=80, 
                             wrap=WORD, font=('Courier', 9))
            text_widget.pack(pady=5)
            
            scrollbar = Scrollbar(text_widget)
            scrollbar.pack(side=RIGHT, fill=Y)
            text_widget.config(yscrollcommand=scrollbar.set)
            scrollbar.config(command=text_widget.yview)
            
            text_widget.insert(END, str(w))
            text_widget.config(state=DISABLED)
            
        except Exception as e:
            messagebox.showerror("Error", f"Failed to get WHOIS info: {str(e)}")
    
    def get_dns_info(self):
        domain_name = self.entry_domain.get().strip()
        if not domain_name:
            messagebox.showwarning("Input Error", "Please enter a domain name!")
            return
            
        try:
            self.clear_results()
            ip_address = socket.gethostbyname(domain_name)
            
            Label(self.results_frame, text=f"DNS Information for {domain_name}:", 
                  font=('Arial', 12, 'bold'), bg='lightblue').pack(pady=10)
            
            result_text = f"IP Address: {ip_address}"
            Label(self.results_frame, text=result_text, font=('Arial', 11), 
                  bg='white', relief=SUNKEN, padx=10, pady=5).pack(pady=5)
            
        except Exception as e:
            messagebox.showerror("Error", f"Failed to get DNS info: {str(e)}")
    
    def clear_results(self):
        for widget in self.results_frame.winfo_children():
            widget.destroy()
    
    def clear_all(self):
        self.entry_domain.delete(0, END)
        self.clear_results()
    
    def run(self):
        self.window.mainloop()

# Create and run the application
if __name__ == "__main__":
    app = DomainInfoGUI()
    app.run()

How the Application Works

The application creates a user-friendly interface with the following components:

  • Domain Input Field ? Users enter the domain name they want to investigate

  • WHOIS Button ? Retrieves comprehensive domain registration information

  • DNS Button ? Performs DNS lookup to get the domain's IP address

  • Clear Button ? Resets the interface and clears all results

  • Results Area ? Displays the retrieved information in a scrollable text widget

Key Features

  • Error Handling ? Catches and displays errors gracefully using message boxes

  • Input Validation ? Ensures users enter a domain name before processing

  • Scrollable Results ? WHOIS information can be lengthy, so results are scrollable

  • Clean Interface ? Organized layout with clear visual separation of components

Example Usage

To use the application:

  1. Run the Python script

  2. Enter a domain name (e.g., "google.com")

  3. Click "Get WHOIS Info" to see registration details

  4. Click "Get DNS Info" to see the IP address

  5. Use "Clear All" to reset and try another domain

Conclusion

This GUI application demonstrates how to combine Tkinter with domain information services to create a practical tool. The application provides both WHOIS and DNS lookup capabilities in an easy-to-use interface, making domain research accessible to users without technical expertise.

Updated on: 2026-03-27T01:26:33+05:30

487 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements