My code is a Tkinter application to create a bill and print it.
When creating the bill, the values are written to a text file. However, the output is not properly aligned, is there any way to specify a template with fixed arguments as positions for each row?
This a minimal program:
#This is a working python script
#Declare and assign field names
vbill_SubTotal = "Sub Total: Rs. "
vbill_TaxTotal = "Tax Total: Rs. "
vbill_RoundOff = "Round Off: Rs. "
vbill_GrandTotal = "Grand Total: Rs. "
#Declare the variables and assign values
vsubTotal = 20259.59
vtaxTotal = 5097.78
vroundOff = 0.27
vgrandTotal = 25358.00
#Concatenate all values into one variable
vbill_contents = vbill_SubTotal + str(vsubTotal) + '\n' +\
vbill_TaxTotal + str(vtaxTotal) + '\n' +\
vbill_RoundOff + str(vroundOff) + '\n'+\
vbill_GrandTotal + (str(vgrandTotal)) + '\n'
#Create a new bill
mybill = "bill.txt"
writebill = open(mybill,"w")
#Write the contents into the bill
writebill.write(vbill_contents)
When this program is executed, the output is written to a notepad file "bill.txt" in your relative path. The data in the file is as follows:
Sub Total: Rs. 20259.59
Tax Total: Rs. 5097.78
Round Off: Rs. 0.27
Grand Total: Rs. 25358.00
The output looks neat at first glance but on looking closer there is no alignment defined. This is my desired output, all decimals should be in one column:
Sub Total: Rs. 20259.59
Tax Total: Rs. 5097.78
Round Off: Rs. 0.27
Grand Total: Rs. 25358.00
I have looked into a lot of tutorials for this and find nothing in the Tkinter framework. The only option I need to explore is to write all this data to a canvas first and align them and then print the canvas itself rather than this text file.
Any help on the quickest way forward? If canvas is my only option, please provide a sample/pointer on the simplest way to use canvas to do this work.