|
| 1 | +__author__ = 'Avinash' |
| 2 | + |
| 3 | +import tkinter as tk |
| 4 | +import socket |
| 5 | +from functools import partial |
| 6 | + |
| 7 | + |
| 8 | +# the main conversion |
| 9 | +def call_convert(rlabel1, inputn): |
| 10 | + try: |
| 11 | + ip = (socket.gethostbyname(inputn.get())) |
| 12 | + rlabel1.config(text="The IP address of domain " + inputn.get() + " is " + ip) |
| 13 | + except Exception: |
| 14 | + rlabel1.config(text="Please enter a valid url and in the form 'www.example.com'") |
| 15 | + return |
| 16 | + |
| 17 | + |
| 18 | +# app window configuration and UI |
| 19 | +root = tk.Tk() |
| 20 | + |
| 21 | +# Gets the requested values of the height and width. |
| 22 | +windowWidth = root.winfo_reqwidth() |
| 23 | +windowHeight = root.winfo_reqheight() |
| 24 | + |
| 25 | +# Gets both half the screen width/height and window width/height |
| 26 | +positionRight = int(root.winfo_screenwidth() / 2 - windowWidth / 2) |
| 27 | +positionDown = int(root.winfo_screenheight() / 2 - windowHeight / 2) |
| 28 | + |
| 29 | +root.geometry("600x200+{}+{}".format(positionRight, positionDown)) |
| 30 | +root.title('Domain to IP Converter') |
| 31 | +root.configure(background='#009688') |
| 32 | +root.resizable(width=False, height=False) |
| 33 | +root.rowconfigure(0, weight=1) |
| 34 | +root.columnconfigure(0, weight=1) |
| 35 | +root.rowconfigure(2, weight=1) |
| 36 | +root.columnconfigure(2, weight=1) |
| 37 | + |
| 38 | +contents = tk.Frame(
AC4F
root) |
| 39 | +contents.grid(row=1, column=1) |
| 40 | + |
| 41 | +domainInput = tk.StringVar() |
| 42 | + |
| 43 | +# label and entry field |
| 44 | +input_label = tk.Label(root, text="Enter domain", background='#009688', foreground="#FFFFFF") |
| 45 | +input_entry = tk.Entry(root, textvariable=domainInput) |
| 46 | +input_label.grid(row=1) |
| 47 | +input_entry.grid(row=1, column=1) |
| 48 | + |
| 49 | +# result label's for showing the IP of a domain |
| 50 | +result_label1 = tk.Label(root, background='#009688', foreground="#FFFFFF") |
| 51 | +result_label1.grid(row=3, columnspan=4) |
| 52 | + |
| 53 | +# button click |
| 54 | +call_convert = partial(call_convert, result_label1, domainInput) |
| 55 | +result_button = tk.Button(root, text="Convert", command=call_convert, background='#FFFFFF', foreground="#009688") |
| 56 | +result_button.grid(row=2, columnspan=4) |
| 57 | + |
| 58 | +root.mainloop() |
0 commit comments