Question

I'm going to make a simple text editor in python for fun. I have a general idea of how I'm going to do it. The only thing I'm having trouble understanding right now is how I will add the bold, italics, and underline options. How would I let the user italicize some text for example? Is there a python module for doing this? Or is it more on the GUI side?

Was it helpful?

Solution

If you are just starting with the GUI I think you should start from Tkinter first. Here is an example to write text in some styles you are looking for.

from Tkinter import *
root = Tk()

text2 = Text(root, height=20, width=50)


## create separate tags for separate fonts
text2.tag_configure('normal', font=('Arial', 20))
text2.tag_configure('italics', font=('Arial', 20,'italic'))
text2.tag_configure('bold', font=('Arial', 20,'bold'))
text2.tag_configure('underline', font=('Arial', 20,'underline'))
text2.tag_configure('all', font=('Arial', 20,'bold','italic','underline'))

##use the tags to print text in a particular font
text2.insert(END,'This text is Normal\n','normal' )
text2.insert(END,'This text is Bold\n', 'bold')
text2.insert(END, "this text is italics\n", 'italics')
text2.insert(END, "this text is underline\n", 'underline')
text2.insert(END, "this text is everything\n", 'all')
text2.pack(side=LEFT)

root.mainloop()

after knowing how Tkinter works you can create separate functions and then bind them to keys to select your own font like.

(ctrl+b) for BOLD
(ctrl+i) for italics
(ctrl+u) for underline

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top