Advertisement
here2share

# Tk_io_buttons.py

May 23rd, 2018
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.50 KB | None | 0 0
  1. # Tk_io_buttons.py
  2.  
  3. import Tkinter as tk
  4.  
  5. def __init__(master):
  6.     frame = Frame(master)
  7.     frame.pack()
  8.  
  9. def toggle_text():
  10.     if button["text"] == "NO":
  11.         button["text"] = "YES"
  12.         label["bg"] = "green"
  13.         button["bg"] = "lightgray"
  14.     else:
  15.         button["text"] = "NO"
  16.         label["bg"] = "red"
  17.         button["bg"] = "darkgray"
  18. def toggle_text1():
  19.     if button1["text"] == "NO":
  20.         button1["text"] = "YES"
  21.         label1["bg"] = "green"
  22.         button1["bg"] = "lightgray"
  23.     else:
  24.         button1["text"] = "NO"
  25.         label1["bg"] = "red"
  26.         button1["bg"] = "darkgray"
  27. def toggle_text2():
  28.     if button2["text"] == "NO":
  29.         button2["text"] = "YES"
  30.         label2["bg"] = "green"
  31.         button2["bg"] = "lightgray"
  32.     else:
  33.         button2["text"] = "NO"
  34.         label2["bg"] = "red"
  35.         button2["bg"] = "darkgray"
  36.  
  37. root = tk.Tk()
  38. root.title("GUI - TEST")
  39.  
  40. button = tk.Button( text="NO", width=12, command=toggle_text, bg='darkgray')
  41. button.grid(row=0, column=1)
  42. label = tk.Label(bg='red', width=6, text='1')
  43. label.grid(row=0, column=2)
  44.  
  45. button1 = tk.Button( text="NO", width=12, command=toggle_text1, bg='darkgray')
  46. button1.grid(row=1, column=1)
  47. label1 = tk.Label(bg='red', width=6, text='2')
  48. label1.grid(row=1, column=2)
  49.  
  50. button2 = tk.Button( text="NO", width=12, command=toggle_text2, bg='darkgray')
  51. button2.grid(row=2, column=1)
  52. label2 = tk.Label(bg='red', width=6, text='3')
  53. label2.grid(row=2, column=2)
  54.  
  55. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement