I have a Python script that asks for user input:
Python File:
confirmation = input("Enter confirmation (Y/S): ")
LFM File:
object Form1: TForm1
Left = 250
Height = 240
Top = 113
Width = 320
Caption = 'Form1'
ClientHeight = 240
ClientWidth = 320
LCLVersion = '3.0.0.2'
object mOutPut: TMemo
Left = 8
Height = 170
Top = 64
Width = 304
Color = clBlack
Font.CharSet = ANSI_CHARSET
Font.Color = clWhite
Font.Height = -13
Font.Name = 'Consolas'
Font.Pitch = fpFixed
Font.Quality = fqDraft
Lines.Strings = (
'moutput'
)
ParentFont = False
ReadOnly = True
ScrollBars = ssAutoBoth
TabOrder = 0
end
object Button1: TButton
Left = 111
Height = 25
Top = 20
Width = 75
Caption = 'Button1'
TabOrder = 1
OnClick = Button1Click
end
object PythonEngine1: TPythonEngine
IO = PythonGUIInputOutput1
Left = 224
Top = 19
end
object PythonGUIInputOutput1: TPythonGUIInputOutput
DelayWrites = True
UnicodeIO = True
RawOutput = True
Output = mOutPut
Left = 48
Top = 19
end
end
PAS File:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls,
PythonEngine, PythonGUIInputOutput, Process;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
mOutPut: TMemo;
PythonEngine1: TPythonEngine;
PythonGUIInputOutput1: TPythonGUIInputOutput;
procedure Button1Click(Sender: TObject);
procedure ExecutePY;
private
public
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.Button1Click(Sender: TObject);
var
s: tstringlist;
begin
//ExecutePY;
s := TStringList.Create;
try
s.LoadFromFile('input.py');
pythonengine1.execstrings(s);
finally
s.Free;
end;
end;
end.
In a program written with the Lazarus IDE I inserted the TPythonEngine and TPythonGUIInputOutput components from the PythonForLazarus component library.
TPythonEngine.IO is pointing to TPythonGUIInput and this in turn has TPythonGUIInput.Output pointing to a Memo. When I run the Python script using TPythonEngine.ExecStrings(TListStrings), in the user input part, the Lazarus InputQuery is displayed for the user to enter the option but the application is frozen waiting for the user input, that is, the InputQuery (box ) freezes the application until the user enters the value. How do I ensure that the user can continue using the application window before entering data into InputQuery?
Before, I needed to display the Python Input data input graphically in the Lazarus application and the PythonGUIInputOutput from the PythonForLazarus library made it possible to execute the script and display the input box, but the application is stuck waiting for user input.