Advertisement
here2share

# Tk_random_color.py

Oct 7th, 2018
268
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. # Tk_random_color.py
  2.  
  3. import Tkinter
  4. from random import randint
  5.  
  6. def random_color():
  7.     rgb = tuple([randint(0,255) for _ in 'rgb'])
  8.     print rgb
  9.     rgb = '#%02x%02x%02x'%rgb
  10.     print rgb
  11.     print
  12.     root.configure(bg=rgb)
  13. #
  14.  
  15. root = Tkinter.Tk()
  16. root.wm_geometry('200x200')
  17. Tkinter.Button(root, text="Press Me!", bg='white', fg='red', command=random_color).pack()
  18.  
  19. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement