Skip to content

Instantly share code, notes, and snippets.

@zed
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zed/11390111 to your computer and use it in GitHub Desktop.
Save zed/11390111 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
"""Leave Start button pressed until Stop button is pressed. (ttk version)
http://stackoverflow.com/q/23353746/
"""
try:
import Tkinter as tk
import ttk
except ImportError: # Python 3
import tkinter as tk
import tkinter.ttk as ttk
SUNKABLE_BUTTON = 'SunkableButton.TButton'
root = tk.Tk()
root.geometry("400x300")
style = ttk.Style()
def start():
button.state(['pressed', 'disabled'])
style.configure(SUNKABLE_BUTTON, relief=tk.SUNKEN, foreground='green')
def stop():
button.state(['!pressed', '!disabled'])
style.configure(SUNKABLE_BUTTON, relief=tk.RAISED, foreground='red')
button = ttk.Button(root, text ="Start", command=start, style=SUNKABLE_BUTTON)
button.pack(fill=tk.BOTH, expand=True)
ttk.Button(root, text="Stop", command=stop).pack(fill=tk.BOTH, expand=True)
root.mainloop()
#!/usr/bin/env python
"""Leave Start button pressed until Stop button is pressed.
http://stackoverflow.com/q/23353746/
"""
try:
import Tkinter as tk
except ImportError: # Python 3
import tkinter as tk
root = tk.Tk()
root.geometry("400x300")
def start():
start_button.configure(relief=tk.SUNKEN, state=tk.DISABLED)
def stop():
start_button.configure(relief=tk.RAISED, state=tk.ACTIVE)
start_button = tk.Button(root, text ="Start", command=start)
start_button.pack(fill=tk.BOTH, expand=True)
tk.Button(root, text="Stop", command=stop).pack(fill=tk.BOTH, expand=True)
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment