I have a text file that assign a numeric value to a parameter with the following line:
designPoint1.SetParameterExpression(Parameter=parameter1, Expression="50")
I want to create a GUI in which user can assign a new value to parameters (for example 20). This GUI has to replace the new value in the previous line so that the result of substitution would be:
designPoint1.SetParameterExpression(Parameter=parameter1, Expression="20")
This is what i've tried to do:
import sys
from tkinter import *
def NewValues():
diamValue = Diameter.get()
cpValue = Cp.get()
cbValue = Cb.get()
gammaValue = GammaRel.get()
epsValue = Epsilon.get()
with open('parametri.txt', 'r') as input_file, open('newparametri.txt', 'w') as output_file:
for line in input_file:
if line.strip() == 'designPoint1.SetParameterExpression(Parameter=parameter1, Expression="50")':
output_file.write('designPoint1.SetParameterExpression(Parameter=parameter1, Expression="diamValue"\n)')
else:
output_file.write(line)
return
def RunSimulation():
pass
return
App = Tk()
Diameter = StringVar()
Cp = StringVar()
Cb = StringVar()
GammaRel = StringVar()
Epsilon = StringVar()
App.geometry("250x200")
App.title("Static Calculator")
AppLabel1 = Label(text="Diameter").grid(row =0,column =0,sticky="W")
AppLabel2 = Label(text="Cp").grid(row=1,column=0,sticky="W")
AppLabel3 = Label(text="Cb").grid(row=2,column=0,sticky="W")
AppLabel4 = Label(text="Gamma Rel").grid(row=3,column=0,sticky="W")
AppLabel5 = Label(text="epsilon").grid(row=4,column=0,sticky="W")
AppEntry1 = Entry(App,textvariable=Diameter).grid(row =0,column =1)
AppEntry2 = Entry(App,textvariable=Cp).grid(row =1,column =1)
AppEntry3 = Entry(App,textvariable=Cb).grid(row =2,column =1)
AppEntry4 = Entry(App,textvariable=GammaRel).grid(row =3,column =1)
AppEntry5 = Entry(App,textvariable=Epsilon).grid(row =4,column =1)
Appbutton1 = Button(App,text = "Update Values",command = NewValues,).grid(row =5,column =1)
Appbutton2 = Button(App,text = "Run",command = RunSimulation,).grid(row =6,column =1)
App.mainloop()
Obviously, the results of this code is:
designPoint1.SetParameterExpression(Parameter=parameter1, Expression="diamValue")
Is it possible to correct this code to reach the goal?
Thanks for every help.