Mar-25-2018, 07:22 AM
(This post was last modified: Mar-25-2018, 07:23 AM by notsolowki.)
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()