Python Forum
[Tkinter] Tkinter Font Color
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Tkinter Font Color
#1
im very very new to python and im trying to change the font color of a very basic tkinter gui. what the script does is read a text file and display it in the tkinter gui. then logs the readings to a log file. im just trying to make the text from Data.txt show up red and the background of the gui text box to be black. im using python 2.7 can someone please help me out thanks in advanced,

import Tkinter as tk
import tkFont
import time
import sys
timeString = time.strftime('%m-%d-%Y')



class App(tk.Tk):

    def __init__(self,*args, **kwargs):
        tk.Tk.__init__(self, *args, **kwargs)
        # ... YOUR widgets here ...
        self.T = tk.Text(self, height=2, width=4, font=("bold", 32, ))
        self.S = tk.Scrollbar(self)
        self.T.config(yscrollcommand=self.S.set)
        self.T.pack(side=tk.LEFT, fill=tk.Y)
        self.S.config(command=self.T.yview)
        self.S.pack(side=tk.RIGHT, fill=tk.Y)
        self.updateWidgets()


    def updateWidgets(self):
        with open('Data.txt') as f:
            newText = f.read()
            p = open( 'Data-Log.txt', 'a' ) #(w= write)(a= append add lines)
            p.write(newText + timeString + '\n' + "////////" + '\n' + '\n')
            p.close()
            
            
        # ... YOUR code for updating the Widgets ...
        #self.T.delete('1.0', tk.END) #delet old text for incoming new text
        self.T.insert(tk.END, newText, foreground="red")
        self.after(1000, self.updateWidgets)

app = App()
app.mainloop()
Reply


Messages In This Thread
Tkinter Font Color - by notsolowki - Mar-25-2018, 07:22 AM
RE: Tkinter Font Color - by Larz60+ - Mar-25-2018, 08:48 AM
RE: Tkinter Font Color - by notsolowki - Mar-26-2018, 10:14 AM
RE: Tkinter Font Color - by notsolowki - Mar-26-2018, 08:28 AM
RE: Tkinter Font Color - by Larz60+ - Mar-26-2018, 11:21 AM
RE: Tkinter Font Color - by notsolowki - Mar-26-2018, 11:24 AM
RE: Tkinter Font Color - by Larz60+ - Mar-26-2018, 04:09 PM
RE: Tkinter Font Color - by notsolowki - Mar-27-2018, 02:10 AM
RE: Tkinter Font Color - by Larz60+ - Mar-27-2018, 04:34 AM
RE: Tkinter Font Color - by notsolowki - Mar-27-2018, 05:09 AM
RE: Tkinter Font Color - by Larz60+ - Mar-27-2018, 10:52 AM
RE: Tkinter Font Color - by notsolowki - Mar-28-2018, 03:53 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Tkinter - How can I change the default Notebook border color? TurboC 5 15,067 May-23-2022, 03:44 PM
Last Post: bigmac
  Can't get tkinter button to change color based on changes in data dford 4 3,577 Feb-13-2022, 01:57 PM
Last Post: dford
  [Tkinter] Trouble changing Font within tkinter frame title AnotherSam 1 4,375 Sep-30-2021, 05:57 PM
Last Post: menator01
Question [Tkinter] Can I set background color for each item in tkinter Combobox? water 1 5,268 Dec-10-2020, 07:48 PM
Last Post: Larz60+
  Tkinter menu font size -method to change tonycat 2 8,035 Oct-11-2020, 02:43 AM
Last Post: tonycat
  tkinter | Button color text on Click Maryan 2 3,512 Oct-09-2020, 08:56 PM
Last Post: Maryan
  [Tkinter] How to Print a list = ['a','b','c'], using tkinter along with a custom font? Pleiades 2 2,470 Sep-15-2020, 03:54 PM
Last Post: Pleiades
  [tkinter] color change for hovering over button teacher 4 8,828 Jul-04-2020, 06:33 AM
Last Post: teacher
  TKINTER - Change font color for night or day Ayckinn 2 4,010 May-24-2020, 09:25 PM
Last Post: Ayckinn
  Tkinter help (color) Florent 2 2,431 Mar-01-2020, 02:59 PM
Last Post: Florent

Forum Jump:

User Panel Messages

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