I have a canvas with various images. The text entered in the text widget is displayed on the canvas. When entering, the text should move up. The entered text can be quite long.
I need to display text on canvas with different font style in its parts. i.e. some words should be displayed in normal font, some in bold or italics. I want use tag system like this. It work with text widget, but not with canvas.
An example of what I want.
In text widget:
<b>This</b> word is bold.
In the canvas: This word is bold
Simplified part of my code:
import tkinter
import tkinter.scrolledtext
def change_txtabs(event):
abilities = txt_txtabs.get(1.0,tkinter.END)
r_abilities = repr(abilities)
if r_abilities != "'\\n'":
main_pct.itemconfig(txtabilities_text,text=abilities)
else:
main_pct.itemconfig(txtabilities_text,text="")
window = tkinter.Tk()
window.geometry('930x565')
txt_txtabs = tkinter.scrolledtext.ScrolledText(window,height=30,wrap='word',undo=True)
txt_txtabs.bind("<KeyPress>", change_txtabs)
txt_txtabs.bind("<KeyRelease>", change_txtabs)
txt_txtabs.place(x=10,y=10,width=300)
main_pct = tkinter.Canvas(bg='white',height=480, width=300)
txtabilities_text = main_pct.create_text((12,432),text="",font="Arial 10",anchor=tkinter.SW,justify=tkinter.LEFT,width=280)
main_pct.place(x=350,y=10)
window.mainloop()