Hi, i was wondering how to change the lable text in Python after clicking a button. For example:

    `from Tkinter import *
    `def onclick():`


        import tkMessageBox

        root = Tk()

        root.title("Pantai Hospital")                              
        L1 = Label(root, text='Welcome to Pantai Hospital!')
        L2 = Label(root, text='Login')

        L3 = Label(root, text = "Username:")
        L3.pack( side = LEFT, padx = 5, pady = 10)
        username = StringVar()
        E1 = Entry(root, textvariable = username, width = 40)
        E1.pack ( side = LEFT)

        L4 = Label(root, text = "Password:")
        L4.pack( side = LEFT, padx = 5, pady = 10)
        password = StringVar() 
        E2 = Entry(root, textvariable = password, show = "*", width = 40)    
        E2.pack( side = LEFT)'`

I want to change those labels 'username' and 'password' and the entry field into another different label after clicking a button. how do I do that?

You could also do this:

from Tkinter import *
root = Tk()
l = Label(text='Good morning!')
def change():
    global l
    l['text'] = 'Good night!'
b = Button(text='Is it night?', command=change)

The main thing you have to do is link a Button to a function which executes instance['text'] = '<some text>.

This article has been dead for over six months. Start a new discussion instead.