Skip to content

Commit

Permalink
Update and rename myip.py to other_pepole/get_ip_gui
Browse files Browse the repository at this point in the history
i try to convert it to GUI , for practice :)
  • Loading branch information
khaled15486 authored Nov 17, 2017
1 parent 266ac85 commit 018f0c6
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 19 deletions.
19 changes: 0 additions & 19 deletions myip.py

This file was deleted.

68 changes: 68 additions & 0 deletions other_pepole/get_ip_gui
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

#**************** Modules Require *****************#
from tkinter import *
import socket
from urllib.request import urlopen

#**************** Get IP commands *****************#
#control buttons
def get_wan_ip():
try :
#get ip from http://ipecho.net/plain as text
wan_ip=urlopen('http://ipecho.net/plain').read().decode('utf-8')
res.configure(text='Wan IP is : '+wan_ip,fg='#600')
except :
res.configure(text='Problem in source : http://ipecho.net/plain',fg='red')
#get local ip
def get_local_ip():
try:
lan_ip=(socket.gethostbyname(socket.gethostname()))
res.configure(text='Local IP is : '+lan_ip,fg='#600')
except:
res.configure(text='Unkown Error',fg='#red')
#**************** about control button *****************#
#show about info and change the button command and place
def about():
global close_app,frame,info
about_app.destroy()
frame=Frame(root,width=350,height=2,bg='blue')
frame.grid(row=2,column=0,columnspan=4)
info=Label(root,text="""
Practice Python
Take idea from here :
https://github.com/geekcomputers/Python/blob/master/myip.py
""",fg='#02F')
info.grid(row=3,column=0,columnspan=4,padx=5)
close_app=Button(root,text='Close',command=close_about,bg='#55F')
close_app.grid(row=4,column=0,columnspan=4,pady=5)
#remove about info and remove close button then return about button in orignal place
def close_about():
global frame,about_app,info
info.destroy()
frame.destroy()
close_app.destroy()
about_app=Button(root,text='about',command=about)
about_app.grid(row=1,column=2,padx=5,pady=5,sticky=W)

#**************** Tkinter GUI *****************#
root=Tk()
root.title ('Khaled programing practice')
#all buttons
res=Label(root,text='00.00.00.00',font=25)
res_wan_ip=Button(root,text='Get Wan IP',command=get_wan_ip)
res_local_ip=Button(root,text='Get Local IP',command=get_local_ip)
about_app=Button(root,text='about',command=about)
quit_app=Button(root,text='quit',command=quit,bg='#f40')
#method grid to install the button in window
res.grid(row=0,column=0,columnspan=4,sticky=N,padx=10,pady=5)
res_wan_ip.grid(row=1,column=0,padx=5,pady=5,sticky=W)
res_local_ip.grid(row=1,column=1,padx=5,pady=5,sticky=W)
about_app.grid(row=1,column=2,padx=5,pady=5,sticky=W)
quit_app.grid(row=1,column=3,padx=5,pady=5,sticky=E)
#run GUI/app
root.mainloop()



0 comments on commit 018f0c6

Please sign in to comment.