Lesson-3: Tkinter Label Color, Font
Tkinter Label Color, Font
import tkinter as tk
pencere=tk.Tk()
pencere.title("Python Tkinter Lessons")
etiket1=tk.Label(pencere,text="Welcome...")
etiket1.pack()
etiket2=tk.Label(pencere,text="Bilişim Teknolojileri...")
etiket2.pack()
pencere.mainloop()
We created a window and created 2 labels in it. Now let’s color these labels .
etiket2=tk.Label(pencere,text="Bilişim Teknolojileri", fg="red")
we can change the label Color by adding red to the FG component. I take a screenshot like below.
etiket1=tk.Label(pencere,text="Dersehoşgeldiniz...",fg="white", bg="purple")
The above line of code makes the color of label 1 white and the background color purple.
import tkinter as tk
pencere=tk.Tk()
pencere.title("Python Tkinter Lessons")
etiket1=tk.Label(pencere,text="Derse Hoşgeldiniz...",fg="white",bg="purple")
etiket1.pack()
etiket2=tk.Label(pencere,text="Bilişim Teknolojileri",fg="red")
etiket2.pack()
pencere.mainloop()
If all these lines of code are executed, a window such as the following appears on the screen.
etiket3=tk.Label(pencere,text="...Python GUI...", fg="blue", font="Times 20 italic")
etiket3.pack()
I added a label called etiket3, and this label Font color will be blue, and the font will be Times 20 points and italic.
import tkinter as tk
pencere=tk.Tk()
pencere.title("Python Tkinter Dersleri")
etiket1=tk.Label(pencere,text="Derse Hoşgeldiniz...",fg="white",bg="purple")
etiket1.pack()
etiket2=tk.Label(pencere,text="Bilişim Teknolojileri",fg="red")
etiket2.pack()
etiket3=tk.Label(pencere,text="...Python GUI...",fg="blue",font="Times 20 italic")
etiket3.pack()
pencere.mainloop()
The screen output of all these codes is as follows.
etiket4=tk.Label(pencere,text="KodlamaEtkinlikleri",fg="green",font="Times 22 bold")
etiket4.pack()
The code line above creates a label called tag4, and the color of this label is Yesil, and the font is times 20 points and bold. The screen output is: