Ask Your Question
3

Is it possible to incorporate formatting for imported text using tkinter?

asked 2022-02-22 11:00:00 +0000

scrum gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2021-07-14 05:00:00 +0000

lalupa gravatar image

Yes, it is possible to incorporate formatting for imported text using tkinter.

One way to do this is to use the Text widget in tkinter which allows for the insertion and manipulation of formatted text.

For example, if you wanted to format some imported text as bold, you could use the Text widget's "tagconfigure" method to create a "bold" tag, and then apply that tag to the desired text using the "tagadd" method.

Here is an example code snippet for formatting imported text as bold in a Text widget:

from tkinter import * # create the tkinter window and Text widget root = Tk() text = Text(root) text.pack() # import the plain text and insert into the Text widget plain_text = "This is some imported text." text.insert(END, plain_text) # configure a "bold" tag for the Text widget text.tag_configure("bold", font=("TkDefaultFont", 12, "bold")) # apply the "bold" tag to the desired text text.tag_add("bold", "1.0", "1.4") root.mainloop() 

In this example, the imported text "This" will be formatted as bold using the "bold" tag that was applied to the Text widget.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-02-22 11:00:00 +0000

Seen: 8 times

Last updated: Jul 14 '21