Hi there, using TKinter

Is it possible to change a buttons text after you've clicked it?

So if a button has text of "hi" and when clicked has text of "Goodbye"?

button_switch = True

def click():
    global button_switch

    if button_switch:
        button_switch = False
    else:
        button_switch = True

This would switch the state of the button but can i change the buttons text to an image or different text?

Thanks in advance

PS: thats a cropped piece of code, the buttons i've used is all basic TKinter stuff.

Actually quite simple using button["text"]:

# explore Tkinter button as simple toggle

import Tkinter as tk  # for Python3 use import tkinter as tk

def toggle_text():
    """toggle button text between Hi and Goodbye"""
    if button["text"] == "Hi":
        # switch to Goodbye
        button["text"] = "Goodbye"
    else:
        # reset to Hi
        button["text"] = "Hi"


root = tk.Tk()
root.title("Click the Button")

button = tk.Button( text="Hi", width=12, command=toggle_text)
button.pack(padx=100, pady=10)

root.mainloop()
Comments
very good example
This question has already been answered. Start a new discussion instead.