How to write the below result in a file in python/How to store the results : Have made a python GUI and now I want to store the variable say Reference and Total cost in a file how can I achieve that?[enter image description here][1]

Have tried writing a file like :

def writetofile():
    import os
    outputname ='tutorial.txt'
    a= "TotalCost"

    myfile = open(outputname,'w')
    myfile.write('File A value is    :  ' + str(a)  +   '\n')
    myfile.close()

    if os.stat(outputname).st_size > 0:
       print("tutorial.txt file has been populated")
    else:
       print("the output value is empty")
       print("The A value should read:     " +  str(a) +  '\n')

writetofile()
    

but only the text is coming not the calculated value of TotalCost


  [1]: https://i.stack.imgur.com/EeR4Q.jpg