modify the color a string of characters in python 3.6 - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: modify the color a string of characters in python 3.6 (/thread-16345.html) Pages:
1
2
|
modify the color a string of characters in python 3.6 - atlass218 - Feb-24-2019 hello; I look for a method python associated to objects that type is str; like the methods : upper(), lower() ... which can help me to change the color of the character string. and the character of string is contained in a TEXT field of a database sqlite3 In addition to this field I have other fields that add to a tkinter 'Text' widget Currently this character string is written in black and I want to change its color without integrating it into the 'Label' widget of tkinter thanks for the help RE: modify the color a string of characters in python 3.6 - Yoriz - Feb-24-2019 python strings don't have a colour attribute. RE: modify the color a string of characters in python 3.6 - atlass218 - Feb-24-2019 how can I modify the color of the string RE: modify the color a string of characters in python 3.6 - buran - Feb-24-2019 It's not clear what you want. (Feb-24-2019, 12:13 PM)atlass218 Wrote: In addition to this field I have other fields that add to a tkinter 'Text' widgetIt looks like you talk about changing color of text in Tkinter widget (e.g. Text) If this is the case check https://stackoverflow.com/questions/14786507/how-to-change-the-color-of-certain-words-in-the-tkinter-text-widget RE: modify the color a string of characters in python 3.6 - atlass218 - Feb-24-2019 hi; normally , what I want to do is partially like this: def CreateTable_loc35R(): conn1_loc35R = sqlite3.connect('bdd/ILS35R/ILS35R.db') curseur1_loc35R = conn1_loc35R.cursor() curseur1_loc35R.execute('''CREATE TABLE IF NOT EXISTS loc35R (id INTEGER PRIMARY KEY,time_loc35R TEXT NOT NULL, monitor_loc35R TEXT NOT NULL,message_loc35R TEXT NOT NULL)''') curseur1_loc35R.close() #add events to the table by pressing the "save" button def Add_To_Table_loc35R(): string_loc35R_approved="information approved by LABO aircraft" message_loc35R_approved=string_loc35R_approved.center(56,'*') string_loc35R_not_approved="information not yet approved by LABO aircraft" message_loc35R_not_approved=string_loc35R_not_approved.center(56,'*') #here, according to the case of the state of the checkbutton if variable_case_correction_loc35R.get ()==0 : #checkbutton no checkmark message_loc35R_get=message_loc35R_non_approuve else: #checkbutton checkmark message_loc35R_get=message_loc35R_approuve time_loc35R_get = str(time.strftime('%d/%m/%y à %H:%M:%S', time.localtime())) monitor_get = str(ent_mon.get()) conn2_loc35R = sqlite3.connect('bdd/ILS35R/ILS35R.db') curseur2_loc35R = conn2_loc35R.cursor() curseur2_loc35R.execute('''INSERT INTO loc35R (time_loc35R,monitor_loc35R,message_loc35R) VALUES (?,?,?)''',(time_loc35R_get,monitor_loc35R_get,message_loc35R_get)) conn2_loc35R.commit() curseur2_loc35R.close()I would like to color the string which is included in the variable 'message_loc35R_approved' in green color RE: modify the color a string of characters in python 3.6 - atlass218 - Feb-25-2019 I forget to indicate the save and check button #save button bt_loc35R_save=Button(contenu_application_loc35R,text='save',font=('arial',12,'bold'),command=Add_To_Table_cev_loc35R) bt_loc35R_save.pack() #creation of the widget check box for confirmation of the correction case_correction_loc35R=Checkbutton(loc35R,font=('arial',14,'bold'), variable=variable_case_correction_loc35R) case_correction_loc35R_ddm_faisceau.configure(text="confirmation of the airplane LABO that the correction is good") case_correction_loc35R.pack() RE: modify the color a string of characters in python 3.6 - buran - Feb-25-2019 Please, understand that string in database has no color. You will store just the string. No formatting properties like color, font, size, etc. You may apply different color when presenting the data to the user. How you would do that will depend on your program - e.g. is it GUI, CLI, web-based... RE: modify the color a string of characters in python 3.6 - atlass218 - Feb-25-2019 In this case how can I modify the color of the string.I have in my case two stringVar : string_loc35R_approved message_loc35R_not_approved but only one will be displayed at the Text tkinter according to the state of the checkbutton and only the content of the string_loc35R_approve will be displayed at green color if the checkbutton is CHECKED RE: modify the color a string of characters in python 3.6 - buran - Feb-25-2019 (Feb-25-2019, 12:34 PM)atlass218 Wrote: will be displayed at the Text tkinter according to the state of the checkbutton (Feb-24-2019, 04:27 PM)buran Wrote: It looks like you talk about changing color of text in Tkinter widget (e.g. Text) RE: modify the color a string of characters in python 3.6 - atlass218 - Feb-26-2019 I try the procedure of the previous link cited, but I have a problem : this is the end of the code of the update fonction of the Text widget tkinter: T_cev_loc35R.insert(END,contenu_table_cev_loc35R) if variable_case_correction_loc35R.get ()==0 : T_cev_loc35R.tag_add("start", "3.5", "3.53") T_cev_loc35R.tag_config("start", foreground="black") else : T_cev_loc35R.tag_add("start", "3.9", "3.49") T_cev_loc35R.tag_config("start", foreground="green") curseur3_cev_loc35R.close()the coloring of the character string is relative to the indexing of the line when I introduce another data into my database the line 3 is changed and is not colored at green because of the condition about "variable_case_correction_loc35R" |