im currently working with tkinter on Python 3.4 I've created code which generates random passwords. It works but they are printed black. I need to colour them. Randomly, based on list with colours. I looked for help in stack via google but found nothing. Closest to my problem was this [How to make the foreground and background colors of a button in Tkinter random but in there labels are colored. I can set foreground but for whole word, not each character. Can You tell me how could i fill every character of my password with random color?
import string, random
from tkinter import Label, Entry, Button, StringVar
import tkinter as tk
root = tk.Tk()
root.configure(background='black')
password = tk.StringVar()
letters = string.ascii_letters
digits = string.digits
chars = letters + digits
password = "".join(random.choice(chars) for x in range(7))
colors = ['red', 'yellow', 'blue', 'lightgreen', 'green',
'white', 'black', 'purple', 'orange', 'pink']
#passwords = "".join(random.choice(colors) for i in password)
# when I used this 7 color names was printed (not colors)
lbl = tk.Label(root, text=password, relief='raised', font='Verdana, 50', bg='lightgray')
lbl.grid(row=0, columnspan=3, padx=5, pady=3)
e1 = tk.Entry(root, bg='black', fg='white')
e1.grid(row=1, columnspan=2, sticky='WE', padx=5, pady=3)
btn = tk.Button(root, text='S T O P', bg='black', fg='orange')
btn.grid(row=1, column=2, columnspan=1, sticky='WE', padx=5, pady=3)
root.mainloop()
Aucun commentaire:
Enregistrer un commentaire