here2share

# Tk_entry_instant_relay.py

Dec 26th, 2021 (edited)
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.40 KB | None | 0 0
  1. # Tk_entry_instant_relay.py
  2.  
  3. import tkinter
  4.  
  5. root = tkinter.Tk()
  6. myvar = tkinter.StringVar()
  7. myvar.set('')
  8. mywidget = tkinter.Entry(root,textvariable=myvar,width=10)
  9. mywidget.pack()
  10.  
  11. def instant_relay(*t):
  12.     t = myvar.get()
  13.     color = 'red blue cyan lightgreen yellow'.split()[len(t)%5]
  14.     mywidget.config(bg=color)
  15.     mywidget.update_idletasks()
  16.  
  17. myvar.trace('w',instant_relay)
  18.  
  19. root.mainloop()
  20.  
Add Comment
Please, Sign In to add comment