Skip to content

Update and rename myip.py to other_pepole/get_ip_gui #261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from Nov 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()