简体   繁体   中英

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM