Tkinter Label with font styles color & background using fg bg text & relief with borderwidth
4.9 هزار بار بازدید -
4 سال پیش
-
https://www.plus2net.com/python/tkint...
This is the basic code to display the window by using Tkinter class.
import tkinter as tk
my_w=tk.Tk()
my_w.geometry('300x100')
my_w.title('www.plus2net.com')
l3 = tk.Label(my_w, text='Welcome', width=15 )
l3.grid(row=1,column=1)
my_w.mainloop()
On this window we added one Label saying Welcome.
We can change the font style by using a tuple and using font option.
my_font1=('times', 18, 'bold') # font style declaring
l3 = tk.Label(my_w, text='Welcome', width=15,font=my_font1,fg='red' )
We can add background colour to this Label by using bg=’yellow’
l3 = tk.Label(my_w, text='Welcome', width=15,font=my_font1, fg='red',bg='yellow' )
Using the option relief
We can manage the border width of the label and also the style of the border by using relief option.
Relief option takes 6 values.
raised, sunken, ridge, solid, flat, groove. These values along with the borderwidth change the border look of the label.
Here is one example.
l1 = tk.Label(my_w, text='raised', width=10,font=my_font1,
fg='red',borderwidth=2, relief='raised' )
This is the basic code to display the window by using Tkinter class.
import tkinter as tk
my_w=tk.Tk()
my_w.geometry('300x100')
my_w.title('www.plus2net.com')
l3 = tk.Label(my_w, text='Welcome', width=15 )
l3.grid(row=1,column=1)
my_w.mainloop()
On this window we added one Label saying Welcome.
We can change the font style by using a tuple and using font option.
my_font1=('times', 18, 'bold') # font style declaring
l3 = tk.Label(my_w, text='Welcome', width=15,font=my_font1,fg='red' )
We can add background colour to this Label by using bg=’yellow’
l3 = tk.Label(my_w, text='Welcome', width=15,font=my_font1, fg='red',bg='yellow' )
Using the option relief
We can manage the border width of the label and also the style of the border by using relief option.
Relief option takes 6 values.
raised, sunken, ridge, solid, flat, groove. These values along with the borderwidth change the border look of the label.
Here is one example.
l1 = tk.Label(my_w, text='raised', width=10,font=my_font1,
fg='red',borderwidth=2, relief='raised' )
4 سال پیش
در تاریخ 1399/10/27 منتشر شده
است.
4,963
بـار بازدید شده