11#!/usr/bin/env python3
22# -*- coding: utf-8 -*-
33
4+ from logging import root
45import socket
56# **************** Modules Require *****************#
67from tkinter import *
@@ -9,7 +10,9 @@ from urllib.request import urlopen
910
1011# **************** Get IP commands *****************#
1112# control buttons
12- def get_wan_ip ():
13+
14+ def get_wan_ip () -> None :
15+ '''get wan ip'''
1316 try :
1417 # get ip from http://ipecho.net/plain as text
1518 wan_ip = urlopen ('http://ipecho.net/plain' ).read ().decode ('utf-8' )
@@ -18,18 +21,17 @@ def get_wan_ip():
1821 res .configure (text = 'Problem in source : http://ipecho.net/plain' , fg = 'red' )
1922
2023
21- # get local ip
22- def get_local_ip ():
24+ def get_local_ip () -> None :
25+ '''get local ip'''
2326 try :
2427 lan_ip = (socket .gethostbyname (socket .gethostname ()))
2528 res .configure (text = 'Local IP is : ' + lan_ip , fg = '#600' )
2629 except :
2730 res .configure (text = 'Unkown Error' , fg = '#red' )
28- # **************** about control button *****************#
2931
3032
31- # show about info and change the button command and place
3233def about ():
34+ '''show about info and change the button command and place'''
3335 global close_app , frame , info
3436 about_app .destroy ()
3537 frame = Frame (root , width = 350 , height = 2 , bg = 'blue' )
@@ -44,30 +46,35 @@ def about():
4446 close_app .grid (row = 4 , column = 0 , columnspan = 4 , pady = 5 )
4547
4648
47- # remove about info and remove close button then return about button in orignal place
48- def close_about ():
49+ def close_about () -> None :
50+ '''remove about info and remove close button then return about button in orignal place'''
4951 global frame , about_app , info
5052 info .destroy ()
5153 frame .destroy ()
5254 close_app .destroy ()
5355 about_app = Button (root , text = 'about' , command = about )
5456 about_app .grid (row = 1 , column = 2 , padx = 5 , pady = 5 , sticky = W )
5557
58+ def start_app () -> None :
59+ '''start the app'''
60+ global root , res , about_app
61+ # **************** Tkinter GUI *****************#
62+ root = Tk ()
63+ root .title ('Khaled programing practice' )
64+ # all buttons
65+ res = Label (root , text = '00.00.00.00' , font = 25 )
66+ res_wan_ip = Button (root , text = 'Get Wan IP' , command = get_wan_ip )
67+ res_local_ip = Button (root , text = 'Get Local IP' , command = get_local_ip )
68+ about_app = Button (root , text = 'about' , command = about )
69+ quit_app = Button (root , text = 'quit' , command = quit , bg = '#f40' )
70+ # method grid to install the button in window
71+ res .grid (row = 0 , column = 0 , columnspan = 4 , sticky = N , padx = 10 , pady = 5 )
72+ res_wan_ip .grid (row = 1 , column = 0 , padx = 5 , pady = 5 , sticky = W )
73+ res_local_ip .grid (row = 1 , column = 1 , padx = 5 , pady = 5 , sticky = W )
74+ about_app .grid (row = 1 , column = 2 , padx = 5 , pady = 5 , sticky = W )
75+ quit_app .grid (row = 1 , column = 3 , padx = 5 , pady = 5 , sticky = E )
76+ # run GUI/app
77+ root .mainloop ()
5678
57- # **************** Tkinter GUI *****************#
58- root = Tk ()
59- root .title ('Khaled programing practice' )
60- # all buttons
61- res = Label (root , text = '00.00.00.00' , font = 25 )
62- res_wan_ip = Button (root , text = 'Get Wan IP' , command = get_wan_ip )
63- res_local_ip = Button (root , text = 'Get Local IP' , command = get_local_ip )
64- about_app = Button (root , text = 'about' , command = about )
65- quit_app = Button (root , text = 'quit' , command = quit , bg = '#f40' )
66- # method grid to install the button in window
67- res .grid (row = 0 , column = 0 , columnspan = 4 , sticky = N , padx = 10 , pady = 5 )
68- res_wan_ip .grid (row = 1 , column = 0 , padx = 5 , pady = 5 , sticky = W )
69- res_local_ip .grid (row = 1 , column = 1 , padx = 5 , pady = 5 , sticky = W )
70- about_app .grid (row = 1 , column = 2 , padx = 5 , pady = 5 , sticky = W )
71- quit_app .grid (row = 1 , column = 3 , padx = 5 , pady = 5 , sticky = E )
72- # run GUI/app
73- root .mainloop ()
79+ if __name__ == '__main__' :
80+ start_app ()
0 commit comments