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

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

            pass

        import tkMessageBox

        root = Tk()

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

        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!')
l.pack()
def change():
    global l
    l['text'] = 'Good night!'
b = Button(text='Is it night?', command=change)
b.pack()
root.mainloop()

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.