Python Forum
modify the color a string of characters in python 3.6
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
modify the color a string of characters in python 3.6
#1
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
Reply
#2
python strings don't have a colour attribute.
Reply
#3
how can I modify the color of the string
Reply
#4
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' 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
It 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/1478...ext-widget
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
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
Reply
#6
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()
Reply
#7
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...
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#8
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
Reply
#9
(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)
If this is the case check https://stackoverflow.com/questions/1478...ext-widget
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#10
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"
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Turtle Star Fill Color Yellow-White Interchanging Color Effect codelab 9 902 Oct-25-2023, 09:09 AM
Last Post: codelab
  doing string split with 2 or more split characters Skaperen 22 2,317 Aug-13-2023, 01:57 AM
Last Post: Skaperen
  How do I check if the first X characters of a string are numbers? FirstBornAlbratross 6 1,427 Apr-12-2023, 10:39 AM
Last Post: jefsummers
Question Help me modify this .txt into .csv with Python mgzz 1 721 Dec-14-2022, 01:38 PM
Last Post: Axel_Erfurt
  How to modify python script to append data on file using sql server 2019? ahmedbarbary 1 1,176 Aug-03-2022, 06:03 AM
Last Post: Pedroski55
Photo Visual studio code unable to color syntax on python interpreter tomtom 4 6,684 Mar-02-2022, 01:23 AM
Last Post: tomtom
Question [SOLVED] Delete specific characters from string lines EnfantNicolas 4 2,143 Oct-21-2021, 11:28 AM
Last Post: EnfantNicolas
  I am writing a car rental program on python. In this function I am trying to modify aboo 2 2,681 Aug-05-2021, 06:00 PM
Last Post: deanhystad
  Extract continuous numeric characters from a string in Python Robotguy 2 2,580 Jan-16-2021, 12:44 AM
Last Post: snippsat
  Python win32api keybd_event: How do I input a string of characters? JaneTan 3 3,726 Oct-19-2020, 04:16 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020