tkinter.Label


Definition
The Label create label fpr
Syntax
tkinter.Label

Parameters
Examples 

Label().grid()
Label().destroy()
The Entry.get() input text verified through Button(command).
from tkinter import*

master=Tk()
master.title("Login")

def validate1():
    if  entry.get()=="pythonlake":
        label1=Label(master, text="Welcome")
        label1.grid(row=0,column=3)
        entry.destroy()
        button.destroy()
        label.destroy()
    else:
        label2=Label(master, text="You are not authorized", background="red", fg="white")
        label2.grid(row=0,column=3)

label=Label(master, text="Enter your username: ")
label.grid(row=0,column=0)
           
entry=Entry(master)
entry.grid(row=0,column=1)

button=Button(master, text="Submit",command=validate1)
button.grid(row=0,column=2)

master.mainloop()









The button command function is used to invoke the message box to display the random value.
from tkinter import*

master = Tk()
master.title("Random Widget")

def random_value():
    import random
    random1=random.random()
    messagebox.showinfo("Random Value is", random1)

labelframe=LabelFrame(master, fg="red", font=14, text="Random value generator")
labelframe.pack(side=BOTTOM)

button = Button(labelframe, text = "Click here", fg="blue", command = random_value)
button.pack(side=BOTTOM)

label = Label(labelframe, text = "Click on button to generate random value")
label.pack(side=BOTTOM)

master.mainloop()





The Label created Label("Python Lake") through Tk() and mainloop().
from tkinter import *

main_loop = Tk()

label = Label(main_loop, text="Python Lake")

label.pack()

main_loop.mainloop()



https://sites.google.com/a/pythonlake.com/www/tkinterlabel/tkinter_Label.png

tkinter.Label().pack()
The method return with:
 from tkinter import Tk
import tkinter

master=tkinter.Tk()

a=tkinter.Label(master,text="hello").pack()

if a=="hello":
    print("Yes, tkinter.Label(master,text='hello').pack() is equal to 'hello'.")
    print("No, tkinter.Label(master,text='hello').pack() is not equal to 'hello'.")
    
master.mainloop()

>>> 
No, tkinter.Label(master,text='hello').pack() is not equal to 'hello'.
>>>

tkinter.button(command=print1)
The button command executed the def print1.
from tkinter import*
import tkinter
    

def print1():
    tkinter.Label(master,text="Thank you").pack()

frame=tkinter.Label(master,text="Python Lake: Welcome").pack()

button=tkinter.Button(master, text="Submit", command=print1).pack()

master.mainloop()






Comments