LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-26-2015, 08:23 AM   #1
barunparichha
Member
 
Registered: Jun 2006
Location: Bangalore,india
Distribution: Linux(Redhat,fedora,suse,ubantu), Solaris (s8/s9/s10/nevada/open-solaris)
Posts: 303

Rep: Reputation: 32
Python showing command output in a frame/label


Hi,

How to redirect python command output to a frame/label in python ?

Code:
import os
res = os.system("ls -l");
Above python script just shows this output to my terminal. I want to display this on some python window like frame/label.


Regards,
Barun
 
Old 08-26-2015, 11:38 AM   #2
weibullguy
ReliaFree Maintainer
 
Registered: Aug 2004
Location: Kalamazoo, Michigan
Distribution: Slackware 14.2
Posts: 2,815
Blog Entries: 1

Rep: Reputation: 261Reputation: 261Reputation: 261
You'll have to use some sort of GUI toolkit. Which one you use will dictate how to display text in a label or other widget.
 
Old 08-27-2015, 12:29 AM   #3
barunparichha
Member
 
Registered: Jun 2006
Location: Bangalore,india
Distribution: Linux(Redhat,fedora,suse,ubantu), Solaris (s8/s9/s10/nevada/open-solaris)
Posts: 303

Original Poster
Rep: Reputation: 32
GUI toolkit will just ease the process of writing your code/design.
But my question is rather very simple and irrelevant of any toolkit you use.

Lets say one of my python function is executing some script as given above, and I have to show this output/error(if any) on a python GUI frame instead of showing on a terminal.
Can you paste me the code to redirect this output to the frame ?

N.B.
This could only be answered by someone who has done some scripting in python. So fine if you do not know this.
 
Old 08-27-2015, 01:49 AM   #4
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Quote:
Originally Posted by barunparichha View Post
GUI toolkit will just ease the process of writing your code/design.
We must live on different planets, because I find writing GUI wrappers a pain in the b*tt!

Quote:
Originally Posted by barunparichha View Post
Lets say one of my python function is executing some script as given above, and I have to show this output/error(if any) on a python GUI frame instead of showing on a terminal.
Can you paste me the code to redirect this output to the frame ?
Yes I can. But I won't. Instead, here are a couple of links that will help you:
https://docs.python.org/3.0/library/tkinter.html
https://docs.python.org/3/library/tk.html
http://www.tkdocs.com/tutorial/index.html

And here's a very simple code snippet to get you started:
Code:
#!/usr/bin/env python3

from tkinter import *

root = Tk()

aWidget = Label(root, text="Hello LinuxQuestions!")
aWidget.pack()

root.mainloop()
Best regards,
HMW
 
Old 08-27-2015, 12:18 PM   #5
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,198

Rep: Reputation: 5307Reputation: 5307Reputation: 5307Reputation: 5307Reputation: 5307Reputation: 5307Reputation: 5307Reputation: 5307Reputation: 5307Reputation: 5307Reputation: 5307
Quote:
Originally Posted by barunparichha View Post
GUI toolkit will just ease the process of writing your code/design.
But my question is rather very simple and irrelevant of any toolkit you use.
No, you do need to choose a GUI toolkit. You need use that toolkit to create the window that will display your output. If the toolkit you want is the one that IDLE uses, then HMW already posted a snippet for that.

Here's one for PySide:

Code:
#!/usr/bin/env python

from PySide import QtGui
import subprocess
import sys


    def main():
        app = QtGui.QApplication(sys.argv)
        window = Window()
        window.show()
        window.setText(subprocess.check_output(['ls', '-l']))
        sys.exit(app.exec_)()


class Window(QtGui.QMainWindow):

        def __init__(self, parent=None):
            super(Window, self).__init__(parent)
            self._text = QtGui.QTextEdit()
            self._text.setReadOnly(True)
            self.setCentralWidget(self._text)

        def setText(self, text):
            self._text.setText(text)


if __name__ == '__main__':
    main()

Last edited by dugan; 08-27-2015 at 03:47 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
STATS command output not showing detail information. manalisharmabe Solaris / OpenSolaris 8 01-13-2014 11:16 AM
[SOLVED] GtkWidget (label) not showing! kalleanka Programming 1 08-25-2011 07:57 AM
Showing command output on the screen while simultaneously logging it. Lufbery Slackware 3 02-04-2010 02:18 PM
How to use wx.Frame in Python jdwilder Programming 3 09-20-2006 08:34 AM
python problem - compiled from source - python -V still showing old version txm123 Linux - Newbie 1 02-15-2006 11:05 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration