Any way to shorten this python GUI? python v3.2 using Tkinter?
-
ip address at the click of a button # shows how to aquire both public and private ip address's and shows them in a text box from tkinter import * import urllib import socket from urllib import * from urllib import request class Application(Frame): .... """ Shows you your ip's. """ .... def __init__(self, master): .... .... """ initialize the frame. """ .... .... super(Application, self).__init__(master) .... .... self.grid() .... .... self.create_widgets() .... def create_widgets(self): .... .... """ Create button and text boxes. """ .... .... # create public ip label .... .... self.pub_lbl = Label(self, text = "Public IP") .... .... self.pub_lbl.grid(row = 1, column = 2, sticky = W) .... .... # create private ip label .... .... self.prv_lbl = Label(self, text = "Private IP") .... .... self.prv_lbl.grid(row = 1, column = 0, sticky = W) .... .... # create ip button .... .... self.ip_bttn = Button(self, text = "IP Address", command = self.reveal) .... .... self.ip_bttn.grid(row = 1, column = 1, sticky = W) .... .... # create text widget to display private ip address .... .... self.prvIP_text = Text(self, width = 15, height = 1, wrap = WORD) .... .... self.prvIP_text.grid(row = 2, column = 0, sticky = W) .... .... # create text widget to display public ip address .... .... self.pubIP_text = Text(self, width = 15, height = 1, wrap = WORD) .... .... self.pubIP_text.grid(row = 2, column = 2, columnspan = 1, sticky = W) .... def reveal(self): .... .... """ Display ip address's. """ .... .... pubIP = urllib.request.urlopen('http://automation.whatismyip.com/n09230945.asp').read() .... .... prvIP = socket.gethostbyaddr(socket.gethostname(... .... .... self.prvIP_text.delete(0.0, END) .... .... self.prvIP_text.insert(0.0, prvIP) .... ....self.pubIP_text.delete(0.0, END) .... ....self.pubIP_text.insert(0.0, pubIP) # main root = Tk() root.title("IP address") root.geometry("300x50") app = Application(root) root.mainloop()
-
Answer:
There is no possible way to shorten the code.
Jared Garrow at Yahoo! Answers Visit the source
Other answers
There is no possible way to shorten the code.
Related Q & A:
- how to zip similar files using python?Best solution by Stack Overflow
- How to add image to QTextBrowser using Python?Best solution by Stack Overflow
- How to plot geo-data using matplotlib/python?Best solution by Geographic Information Systems
- How to verify a JWT using python PyJWT with public key?Best solution by Stack Overflow
- How to create a graph using python?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.