How to provide a single line caption in Tkinter GUI application : Label Widget


Label Widget

Label widgets implement a box container used to place
text
image

Syntax:

            Label(master, options.........)

master : master is nothing but the window object (parent window for which Label needs to be created )

options : options are used to shape the label separated by comma's and to define action on click. Below is the list of options, can be passed while creating label.


  • bg : 
    • to give a colour to the Label Widget background.
  • bd : 
    • to select border of the Widget.
  • fg : 
    • to give text a colour in Widget.
  • text : 
    • to display the text as a message or single line.
  • font : 
    • to give font to the text inside Label Widget.
  • cursor : 
    • to set cursor as arrow or dot when hover on Label Widget.
  • bitmap : 
    • graphical display if bitmap is set equals to a bitmap or image.
  • anchor : 
    • to position the text if Label Widget has more space than the needed text. 
  • height : 
    • vertical dimensions of the Label Widget.
  • width : 
    • width of Label w.r.t. characters in one line.
  • image : 
    • to set a static image in Label, set this option to an image object.
  • justify : 
    • to justify the text position, LEFT, CENTER or RIGHT.
  • padx : 
    • extra space to left and right of the text.
  • pady : 
    • extra space above and below of the text.
  • relief : 
    • to give a decorative border, default s FLAT.
  • underline : 
    • to display an underline below the text, by setting the position. from 0 to set position, it will underline.
  • wraplength : 
    • to limit the number of character to display in each line, default is 0 means on a new line it will break.

there are few options which may not work on mac, but work finely on windows and linux

Example for the Label widget, output screen shot is on top of this post


# program to create Label widget

try:
from Tkinter import *
except:
from tkinter import *

mw = Tk()
mw.geometry(
'400x100+10+10')
mw.title(
"AETies : Automation Expert Technologies")

label = Label(mw
, text='Enter Name')
label.pack()

mw.mainloop()



Comments

My photo
Techno Xpresss
Bangalore, Karnataka, India