modifier le widget text tkinter
Bonjour à tous,
je m'amuse à faire un éditeur de texte mais problème, j'aimerais changer la couleur du texte mais pas tout le texte.
du coup j'ai récupéré la position du curseur puis j'ai ajouté un tag de mon curseur jusqu'à la fin du texte et je configure ce tag de la couleur que je souhaite mais cela ne marche pas et mes recherches étaient sur du texte déjà présent dans le widget text.
voici mes fonctions :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| def color_blue():
position_cursor = texte.index(INSERT)
texte.tag_add("start", position_cursor)
texte.tag_config("start", foreground="blue")
#texte.config(foreground="blue")
font_color.config(foreground="blue")
def color_red():
position_cursor = texte.index(INSERT)
texte.tag_add("start", position_cursor)
texte.tag_config("start", foreground="red")
#texte.config(foreground="red")
font_color.config(foreground="red")
def color_green():
position_cursor = texte.index(INSERT)
texte.tag_add("start", position_cursor)
texte.tag_config("start", foreground="green")
#texte.config(foreground="green")
font_color.config(foreground="green")
def color_black():
position_cursor = texte.index(INSERT)
texte.tag_add("start", position_cursor)
texte.tag_config("start", foreground="black")
#texte.config(foreground="black")
font_color.config(foreground="black") |
En fait mes fonctions modifient aussi la couleur du text présent dans le bouton pour savoir la couleur sélectionnée.
Et voici mes boutons :
Code:
1 2 3 4 5 6 7 8
| font_color = Menubutton(frame, text="color", relief=FLAT)
fonts_list_color = Menu(font_color)
font_color.config(menu=fonts_list_color)
fonts_list_color.add_command(label="bleu", foreground="blue", command= color_blue)
fonts_list_color.add_command(label="rouge", foreground="red", command= color_red)
fonts_list_color.add_command(label="vert", foreground="green", command= color_green)
fonts_list_color.add_command(label="noir", foreground="black", command= color_black)
font_color.pack(side=LEFT) |
Pouvez-vous m'aider ?
merci !