I am developing a software and in that I want a window, that will display the output thrown by the terminal (like a package manager does ). Example, if i give the install command, the installation process should be outptutted to my window and not the terminal. Is there a way to do this in python Gtk?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
If you are on Linux (as you state), something like this should work:
The nonblocking read idea is from here.
Using a Label to display the text:
You can use the subprocess module and the os module to get back the terminal output.You can check this question.
I've been trying to do this and really struggling. I couldn't get the first example working and moved quickly onto the 2nd.
Using the 2nd example above (Using Label to display text) and found that this works fine with Python 2.7 but I'm trying to use Python3 and some things just don't work.
I struggled for ages trying to convert to Python3 and had to change some of the imports and change gtk to Gtk which got it mostly working but the thing that really stumped me was due to Python3 using utf-8 codes. I finally got it working by modifying "the non_block_read" function changing the returned text from utf-8 to string and coping with the return None case.
I hope this helps.
For completeness I attach my working code:-