Is there a way of putting the Python Shell output in a tkinter window?

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

Was this solution helpful to you?

Other answers

There is no possible way to shorten the code.

Related Q & A:

Just Added Q & A:

Find solution

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.