Attributes of Lable and Pack | python Tkinter GUI tutorial

 Attributes of Lable and Pack | python Tkinter GUI tutorial

  • Important Lable option
text Add the text
bg background
fg foreground
font sets the font
padx x padding
pady y padding
relief border styling -( SUNKEN, RAISED, GROOVE, RIDGE )

Example

from tkinter import *
root = Tk()
root.geometry("444x233")
root.title("my GuI with shreyas")

title_label = Label(text='''Data structures are used to store data in a
\ncomputer in an organized form. In C language
\nDifferent types of data structures are;
\nArray, Stack, Queue, Linked List Tree.''',
bg ="#d79eeb",fg ="black",padx=20, pady=94, font = ("Comic Sans Ms", 19, "bold"), borderwidth=3,
relief=RAISED)

title_label.pack()

root.mainloop()

Output



Important Pack options

side top, bottom, left, right
anchor north(n), east(e), wast(w), south(s)

Example

from tkinter import *
root = Tk()
root.geometry("444x233")
root.title("my GuI with shreyas")

title_label = Label(text='''Data structures are used to store data in a
\ncomputer in an organized form. In C language
\nDifferent types of data structures are;
\nArray, Stack, Queue, Linked List Tree.''',
bg ="#d79eeb",fg ="black",padx=20, pady=94, font = ("Comic Sans Ms", 19, "bold"), borderwidth=3,
relief=RAISED)

title_label.pack(side="bottom", anchor="nw")

title_label.pack()

root.mainloop()

Output



Fill, padx & pady


fill x, y
title_label.pack(side="bottom", anchor="nw", fill="x")