Skip to content Skip to sidebar Skip to footer

Python Compiler Connected To A Button

Is it possible to connect the Python compiler to a single button called run? Using PQT4 for Python 3, I have a run button, and a text editor, when the user clicks run I would like

Solution 1:

Have you tried to run the code in an interactive interpreter instance? Interactive Console Objects

Explanation of Interactive console objects

When you import the class and create a new instance you could then run code without interrupting the main python thread.

from code import InteractiveInterpreter

code1 = """
def foo():
    print notDefined

foo()
"""

code2 = """
def baz(spam):
    print spam

baz('eggs')
"""

interpreter = InteractiveInterpreter()
interpreter.runcode(code1)
interpreter.runcode(code2)

outputs :

Traceback (most recent calllast):
  File "<string>", line 5, in<module>
  File "<string>", line 3, in foo
NameError: global name 'notDefined'isnot defined
eggs

Post a Comment for "Python Compiler Connected To A Button"