Advertisement
uottawamakermobile

Hex Colour Generator (with test)

Apr 6th, 2020
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. from random import choice ## random is a module and choice is a function
  2. from tkinter import*
  3.  
  4. hex_chars = ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'] ## create the list of characters from which to choose
  5. colour_code = '#' ## this is the start of any colour code in python
  6.  
  7. for i in range (0,6):
  8.     colour_code = colour_code + choice(hex_chars)
  9.  
  10. print ('The hexadecimal colour code generated is:' ,colour_code)
  11.  
  12.  
  13. my_window =Tk() ##function in tkinder that opens a window
  14. my_canvas = Canvas (my_window,width=200,height=200,background= colour_code) ## the window's size and color is defined here
  15. my_canvas.grid(row=0,column=0)
  16. my_window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement