How To Change Label Text In Python
Label, Text, Entry and Message Widget in Python
Label
Labels are used to display texts and images.
The label tin can but display text in a unmarried font, only the text may bridge more than one line.
Syntax
Here is the elementary syntax to create this widget −
due west = Label ( main, selection=value, ... )
Parameters
master − This represents the parent window.
options − Here is the list of near usually used options for this widget. These options can be used as key-value pairs separated by commas.
Various options of Characterization widget:
- ballast: This option controls where the text is positioned. The default anchor is Center.Other possible values are NW(N W is top left), N, NE(North East is top correct), W, E, SW(South West is bottom left), S, SE(South East is bottom right)
- bg : The normal groundwork color displayed behind the label and indicator.
- bd : The size of the edge effectually the indicator. Default is 2 pixels.
- cursor : If you lot set this option to a cursor name (arrow, dot etc.), the mouse cursor will change to that design when information technology is over the label.
- bitmap : Ready this selection equal to a bitmap or image object and the label will display that graphic.
- font : If y'all are displaying text in this label (with the text or textvariable option, the font option specifies in what font that text will be displayed.
- fg : If yous are displaying text or a bitmap in this characterization, this option specifies the color of the text. If you lot are displaying a bitmap, this is the color that will appear at the position of the 1-bits in the bitmap.
- tiptop : The vertical dimension of the new frame.
- image : To display a static image in the label widget, set this option to an epitome object.
- text : To display 1 or more lines of text in a label widget, set this option to a string containing the text. Internal newlines ("northward") will force a line break.
- textvariable : To slave the text displayed in a label widget to a control variable of grade StringVar, set this option to that variable.
- underline : You lot can display an underline (_) beneath the nth alphabetic character of the text, counting from 0, by setting this choice to north. The default is underline=-i, which ways no underlining.
- width: Width of the label in characters (not pixels!). If this option is not ready, the label will be sized to fit its contents.
- relief : Specifies the appearance of a decorative border around the label. The default is Apartment; for other values.
Case
""" Author : ITVoyagers (itvoyagers.in) Date :18th March 2020 Description : Program to show use of Label widget """ from tkinter import * root = Tk() var = StringVar() characterization = Label( root, textvariable=var, relief=RAISED ) var.gear up("Welcome to itvoyagers.in") label.pack()
OUTPUT
Text
The Text widget is used to display the multi-line formatted text with various styles and attributes. The Text widget is by and large used to provide the text editor to the user.
A text widget manages a multi-line text area.
The Text widget also facilitates u.s.a. to utilize the marks and tabs to locate the specific sections of the Text.
Nosotros can likewise use the windows and images with the Text as it tin can too be used to display the formatted text.
Syntax
Here is the simple syntax to create this widget −
w = Text( primary, choice=value, ... )
Parameters
master − This represents the parent window.
options − Hither is the list of most commonly used options for this widget. These options tin be used as primal-value pairs separated past commas.
Diverse options of Text widget:
- bg : The normal groundwork color displayed.
- bd : The size of the border around the indicator. Default is 2 pixels.
- font :The font type of the text.
- fg : The text color of the widget.
- acme : The vertical dimension of widget lines.
- state : It the state is fix to DISABLED, the widget becomes unresponsive to the mouse and keyboard unresponsive.
- width: Width of the text widget in characters. If this option is not fix, the text will be sized to fit its contents.
- highlightbackground : The highlightcolor when the widget doesn't has the focus.
- highlightthickness : The thickness of the focus highlight. The default value is 1.
- highlighcolor : The color of the focus highlight when the widget has the focus.
- relief : Specifies the appearance of a decorative border around the text widget. The default is Flat; for other values.
Example
""" Author : ITVoyagers (itvoyagers.in) Engagement :18th March 2020 Description : Programme to evidence utilize of Text widget """ from tkinter import * root = Tk() txt = Text( root, fg = 'orange' ,bd=10,bg="black" ,relief=RAISED ) txt.insert(INSERT,"Welcome to itvoyagers.in n") txt.insert(INSERT,"This code is for Text Widget n") txt.insert(INSERT,"Enjoy learning with itvoyagers north") txt.pack()
OUTPUT
Entry
The Entry widget is a standard Tkinter widget used to enter or brandish a unmarried line of text.
The entry widget is used to enter text strings. This widget allows the user to enter one line of text, in a single font.
To enter multiple lines of text, utilize the Text widget.
Syntax
Here is the simple syntax to create this widget −
westward = Entry( master, option=value, ... )
Parameters
principal − This represents the parent window.
options − Here is the list of most ordinarily used options for this widget. These options tin can be used as key-value pairs separated by commas.
Various options of Entry widget:
- bg : The normal background color displayed.
- bd : The size of the edge around the indicator. Default is 2 pixels.
- font :The font type of the text.
- fg : The text colour of the widget.
- pinnacle : The vertical dimension of widget lines.
- state : The default is state=NORMAL, but you can utilize state=DISABLED to gray out the command and make information technology unresponsive. If the cursor is currently over the checkbutton, the state is ACTIVE.
- prove : Commonly, the characters that the user types announced in the entry. To make a .countersign. entry that echoes each character as an asterisk, set bear witness="*".
- justify : If the text contains multiple lines, this selection controls how the text is justified: CENTER, LEFT, or RIGHT.
- textvariable : To slave the text displayed in a entry widget to a control variable of class StringVar, set up this choice to that variable.
- width: Width of the entry widget in characters. If this option is not set, the entry will exist sized to fit its contents.
- highlightbackground : The highlightcolor when the widget doesn't has the focus.
- highlightthickness : The thickness of the focus highlight. The default value is 1.
- highlighcolor : The color of the focus highlight when the widget has the focus.
- relief : Specifies the appearance of a decorative edge around the text widget. The default is Apartment; for other values.
- cursor : If you lot gear up this option to a cursor name (arrow, dot etc.), the mouse cursor will alter to that blueprint when it is over the checkbutton.
Example
""" Author : ITVoyagers (itvoyagers.in) Date :18th March 2020 Description : Program to evidence use of Entry widget """ from tkinter import * root=Tk() var1=StringVar() var2=StringVar() itv1=Label(root,text="Username").grid(row=1,column=0) itv2=Entry(root,textvariable=var1,bd=10, fg='orangish',bg = 'black', font = 'Helvetica').grid(row=i,cavalcade=1) itv1=Characterization(root,text="Countersign").grid(row=2,column=0) itv2=Entry(root,show="*",textvariable=var2,bd=10, fg='orange',bg = 'black').grid(row=2,cavalcade=1) def submit(): impress("welcome",var1.go()) print("your countersign is",var2.become()) b=Button(root,text="Submit",control=submit).grid()
OUTPUT
Message
The bulletin widget shows the text messages to the user which can non be edited.
This widget provides a multiline text, automatically breaking lines and justifying their contents.
Its functionality is very like to the one provided past the Label widget, except that it can besides automatically wrap the text, maintaining a given width or aspect ratio
The message text contains more one line. Notwithstanding, the message tin simply exist shown in the single font.
Syntax
Hither is the simple syntax to create this widget −
w = Message( primary, option=value, ... )
Parameters
main − This represents the parent window.
options − Here is the listing of most commonly used options for this widget. These options can exist used every bit key-value pairs separated by commas.
Diverse options of Message widget:
- anchor: This option controls where the text is positioned. The default ballast is Eye.Other possible values are NW(North Due west is top left), N, NE(North Eastward is top right), W, E, SW(South W is bottom left), Due south, SE(South East is bottom right)
- bg : The normal background color displayed backside the Message widget.
- bd : The size of the edge around the indicator. Default is two pixels.
- font : If you are displaying text in this widget (with the text or textvariable selection, the font selection specifies in what font that text will exist displayed.
- fg : If yous are displaying text or a bitmap in this label, this pick specifies the colour of the text. If you are displaying a bitmap, this is the color that will appear at the position of the ane-$.25 in the bitmap.
- height : The vertical dimension of the new frame.
- image : To display a static image in the widget, set up this choice to an image object.
- text : To display one or more lines of text in a message widget, set this pick to a string containing the text. Internal newlines ("n") will strength a line break.
- textvariable : To slave the text displayed in a message widget to a control variable of grade StringVar, prepare this option to that variable.
- width: Width of the characterization in characters (not pixels!). If this option is not prepare, the widget will be sized to fit its contents.
- relief : Specifies the appearance of a decorative border around the widget. The default is FLAT; for other values.
Example
""" Author : ITVoyagers (itvoyagers.in) Engagement :18th March 2020 Description : Program to show use of Message widget """ import tkinter from tkinter import * root=Tk() var=StringVar() itv1=Message(root,textvariable=var,relief=RAISED) var.ready("Welcome to itvoyagers.in") itv1.pack() def helloCallBack(): tkinter.messagebox.showinfo("I am title","Bask Learning with itvoyagers") B=tkinter.Push(root,text="Click Me",command=helloCallBack) B.pack()
OUTPUT
Annotation
Label | Message | Entry | Text |
---|---|---|---|
Information technology is non-editable widget | It is non-editable widget | It is editable widget | It is editable widget |
It is single line which can span to multi-line | Information technology is multi-line widget | It is single line widget | Information technology is multi-line widget |
Displays text | Displays text message | Tin brandish text to user and accept text from user | Can display text to user and have text from user |
You tin can likewise bank check following posts to know more about tkinter and GUI
- What is tkinter?
- Layout / Geometry Manager in Python
- GUI programming in Python and Python GUI Library
- Events and Bindings in Python forth with Widget configuration and styling
- Fonts Names, Font Descriptors, System Fonts, Text formatting, Borders, Relief Styles in Python
- Canvas widget of tkinter module – Python
- Widgets in tkinter module – Python
- Button, Checkbutton & Radiobutton Widget in Python
- Best post on Menu and Menubutton Widget of tkinter
- Best post- Listbox and Scrollbar(Slider) Widget-Python
- Best mail on Frame Widget of tkinter in Python
- All-time mail service on Spinbox and Calibration Widget in Python
- All-time mail- LabelFrame, Toplevel, PanedWindow widgets
- Best postal service: message box widget and its methods
- Best post:Dimensions, Anchors, Bitmaps & Cursors in Python
Source: https://itvoyagers.in/label-text-entry-message-widget-in-python/
Posted by: smileyfres1968.blogspot.com
0 Response to "How To Change Label Text In Python"
Post a Comment