pythontkinterprintinginserttext-widget

How can I insert text and variables into a text box in Python tkinter without elements being contained by {}


I am trying to use a text widget in tkinter to display the output of my code.

sequence = ("This peptide contains ", len(Peptide), "total residues", "\n")
text.insert("current", sequence)

this seems to work, except for that when it is printed, the elements are separated by {}.

I would prefer for the output to not have these parenthesis, and read like: "This peptide contains 17 total residues". Is there a way to do this?

Thank you


Solution

  • It is because sequence is a tuple. Try changing it to

    sequence = "This peptide contains {} total residues\n".format(len(Peptide))