Python Forum
Interacting with python console while program is running
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Interacting with python console while program is running
#1
Hello,

I would like to write a program with a gui, which is able to interact with a python console. I would like to draw something in the gui, send the values to the console and there I can calculate something and plot the data. Do I have to take two consoles to run something like this, or is it possible to execute the gui in a second thread and I'm able to use the python console to plot or calculate something with the data I got from the gui?
Attached is a sketch, which shows what I would like to do.
At the end it should be possible to create something like simulink with matlab.

[Image: spyder.png?part=0.1&view=1&vt=ANaJVrH9wg...uwZPhqiCyE]

Best regards
Reply
#2
One way to do this could be to incorporate a python console in your GUI application. I have an example of how this can be done in pygtk. I'm not the author of this program (see the credits at the top of the file), it was part of the Umit project but as you see it was free software under GPLv2 when I downloaded it a long time ago. It still runs under python 2.7 and it is basically both a pygtk widget and a python console.

This program could be extended by adding widgets to draw anything you want and the console could access directly the drawing data.

The program is not very long, so I think it can be rewritten for other gui toolkits and versions of python without too much effort. The file is here: umitconsole.py
Reply
#3
I visited the pygtk website and downloaded the most current version, which is for Python 2.7 and was released on 2012-02-09. There appears to be no version for Python 3.x and since nothing has been changed for 6 years this module is no longer actively developed. The msi installer for Windows is 32 megabytes, so you'll be adding 32 MB to your distribution if you publish just to include it.
You're probably better off using the Text widget in tkinter since what you're proposing would only require strict control over keyboard and mouse input in it through event handlers, use of exec() and eval() to process lines, and then capturing their output by redirecting the standard out and standard error streams to capture them and display them in the Text widget after the line of code is entered. If you can do this, you have complete control to add whatever features you your standard console implementation.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Why is the program not running? Is there a logical or syntax problem? behi00 10 1,999 Apr-01-2023, 12:50 AM
Last Post: woooee
  Embed Python console in GUI application deanhystad 5 13,794 Jun-04-2021, 05:10 PM
Last Post: deanhystad
  Running cli program within a wx window? t4keheart 2 2,728 Jan-23-2020, 04:50 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020