Button 표시가 눌렸을 때의 동작을 설정하려면 Button 인스턴스에 command 속성을 설정해야 한다.
from tkinter import Tk, StringVar, Button
def whenPressed():
if buttonText.get()=="홀수번째":
buttonText.set("짝수번째")
else:
buttonText.set("홀수번째")
if __name__ == "__main__":
root = Tk()
root.title("Button 창")
buttonText = StringVar()
buttonText.set("홀수번째")
simpleButton = Button(root, textvariable=buttonText)
simpleButton["command"] = whenPressed
simpleButton.pack()
root.mainloop()

