0

I´m trying to execute an external script (named EC.py) by pressing a button on my GUI (named BEN.py) and I want it to be inserted on a list (list1) in my GUI.

My external script (EC.py) is like this:

import scipy
import numpy as np
from scipy import misc
from scipy import ndimage

I = scipy.misc.imread('lena.jpg').astype(int) 
J = (I/10)*10
K = J + 10
Print K

and my GUI (BEN.py) code is:

import os
import Tkinter as tk
import ttk

def Execute():
EC.K
list1.insert(END, K)

my button widget:

mybutton = Button(myGUI, text=”Execute Code”, command = Execute).pack()

my output list:

list1 = Listbox(myGUI, height=20, width=80)

Everything goes reasonably fine, except that just by running my GUI code it already reads the EC.py script, before I press the button. What I want is to get this script to run only when I press the button.

1
  • You might want to read up on modules. Commented Mar 26, 2015 at 13:03

1 Answer 1

1

I suppose (because you didn't wrote complete source code) you wrote import EC before calling EC.K Of course Python produce EC.pyc (compiled version) at startup to optimise multi module imports and validate the syntaxe of all implied modules.

What you want in a way is to have dynamical generated code. EC.py I don't focused on security issues of this behaviour but the simplest way is to use:

try: execfile ("EC.py")
except Exception,msg:
    print msg
raise
Sign up to request clarification or add additional context in comments.

1 Comment

Sorry @Jerome, I´m new to python and some things are still very confusing to me. You are right when you supposed that I imported EC.py before calling EC.K. My doubt is where to include the piece of code you suggested above? On BEN.py?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.