Jump to content
volev

How to execute function in Python script

Recommended Posts

Hi for all.

 

Please help - how to run a function inside a Tkinter GUI application and get its result (or tuples of results). I successfully launch my application, but cannot understand, how do this simple step.

 

for example: we have such function in __main__.py:

def run_settings():

    global vid
    vid.set(cv2.CAP_PROP_SETTINGS, 1) #launch webcam settings

 

How I can run it from Delphi via Python4Delphi?!

 

Sincerely

 

Edited by volev

Share this post


Link to post

Something like:

 

var SL := TStringList.Create;
try
  SL.LoadFromFile('__main__.py');
  GetPythonEngine.ExecStrings(SL);
  Mainmodule.run_settings();
finally 
  SL.Free;
end;

 

  • Like 1

Share this post


Link to post
14 hours ago, pyscripter said:

Something like:

 


var SL := TStringList.Create;
try
  SL.LoadFromFile('__main__.py');
  GetPythonEngine.ExecStrings(SL);
  Mainmodule.run_settings();
finally 
  SL.Free;
end;

 

 

Thanks for answer

Unfortunately it didn't work for me. I use classes in the program - one for the main window, the second additional for working with the camera. I tried to call a class instance method - an error, I wrote a function in python code that calls - the result is the same

 

P4D_opencv_pillow.ZIP

Edited by volev

Share this post


Link to post

Maximum simplifying of program:

 

Only one Tkinter window with one arithmetic function. Program not working as it should (access violation error)

 

 

P4D - 02.ZIP

Share this post


Link to post

Hi 4 all.

 

I see that the problem is in the use of tkinter mainloop. If there are only analytical functions in the Python script, then the call works. I can't find a solution to this problem

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×