1

CORRIGE TP 1 : Sauvegarde des mots de passe générés (mode simple non opti)

 11 months ago
source link: https://gist.github.com/GravenilvecTV/ee1fca319994eb11fd53db0cc25f1082
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Sauvegarde des mots de passe générés (mode simple non opti) · GitHub

Instantly share code, notes, and snippets.

CORRIGE TP 1 : Sauvegarde des mots de passe générés (mode simple non opti)

import string
from random import randint, choice
from tkinter import *
import webbrowser

def google_search():
webbrowser.open_new('https://www.google.com/search?client=firefox-b-d&q=password+generator')

def generate_password():
password_min = 8
password_max = 24
all_chars = string.ascii_letters + string.punctuation + string.digits
password = "".join(choice(all_chars) for x in range(randint(password_min, password_max)))
champ_password.delete(0, END)
champ_password.insert(0, password)
with open('password.txt', 'w+') as file:
file.write(password+'\n')

def last_passwords():
with open('password.txt', 'r+') as file:
title.delete(0, END)
title.insert(0, file.read())
file.close()

#creer une fenetre
window = Tk()

window.title("Password_generator")
window.geometry("720x480")
window.minsize(320, 320)
window.config(bg="#4065A4")
window.iconbitmap("digital-key.ico")

#creer une boite
frame = Frame(window, bg='#4065A4')

#creer une image
width = 300
height = 300
image = PhotoImage(file='pword.png').zoom(35).subsample(32)

#creation d'un canevas
canvas = Canvas(frame, width=width, height=height, bg='#4065A4', bd=0, highlightthickness=0)

#mettre l'image dans le canevas
canvas.create_image(width/2, height/2, image=image)
canvas.grid(row=0, column=0, sticky=W)

#creer une sous boite
sub_frame = Frame(frame, bg='#4065A4')

#creer un titre
#title = Label(sub_frame, bg='black', font=('Helvetica', 20), fg='white')
#title.pack()

#Ecran affichant le dernier password
title = Entry(window, bg='white', fg='red')
title.pack(side=TOP)
title2 = Button(window, text='lock_with_ink_pen last_password', fg='black', command=last_passwords)
title2.pack(side=TOP)

#creer un champs
champ_password = Entry(sub_frame, bg='#4065A4', font=('Helvetica', 20), fg='white')
champ_password.pack()

#creer un bouton
clic_ok = Button(sub_frame, text='lock_with_ink_pen Generate lock_with_ink_pen', bg='#4065A4', font=('Helvetica', 20), fg='white', command=generate_password)
clic_ok.pack(fill=X)

#packer sub_frame
sub_frame.grid(row=0, column=1, sticky=W)
#Affiche la boite
frame.pack(expand=YES)

#Creation d'une barre de menu
menu_bar = Menu(window)

#creer un 1er menu
file_menu = Menu(menu_bar, tearoff=0)
file_menu.add_command(label="mag_right search on google", command=google_search)
file_menu.add_command(label="🗙 Exit", command=window.quit)
menu_bar.add_cascade(label="file_folder File", menu=file_menu)

#Configurer notre fenetre pour ajouter le menu_bar
window.config(menu=menu_bar)

#Afficher la fenetre
window.mainloop()

from tkinter import *
from string import *
from random import *

def password_gene():
t = digits + ascii_letters
max = 7
min = 4
password = "".join(choice(t) for x in range(randint(min, max)))
champ_password.delete(0, END)
champ_password.insert(0, password)

with open("password.tkt", "a+") as file:
    file.write(password + '\n')


with open("password.tkt", "r+") as file:
    last_password.delete(0, END)
    t = file.readlines()
    g = len(t) - 2
    last_password.insert(0, t[g])
    file.close()

Window

window = Tk()
window.title("Generateur")
window.maxsize(1080, 720)
window.minsize(780, 420)
window.iconbitmap("Rdm/bb.png")
window.config(background='#4065A4')

creer une boite

frame = Frame(window, bg='#4065A4')

creer une image

width = 300
height = 300
image = PhotoImage(file='Rdm/bb.png').zoom(35).subsample(32)

creation d'un canevas

canvas = Canvas(frame, width=width, height=height, bg='#4065A4', bd=0, highlightthickness=0)

mettre l'image dans le canevas

canvas.create_image(width / 2, height / 2, image=image)
canvas.grid(row=0, column=0, sticky=W)

creer une sous boite

sub_frame = Frame(frame, bg='#4065A4')

creer un titre

title = Label(sub_frame, text="Mot de passe", bg='#4065A4', font=('Helvetica', 20), fg='white')
title.pack()

creer un champs

last_password = Entry(window, bg='#4065A4', font=('Helvetica', 20), fg='white')
last_password.pack()

creer un champs

champ_password = Entry(sub_frame, bg='#4065A4', font=('Helvetica', 20), fg='white')
champ_password.pack()

creer un bouton

clic_ok = Button(sub_frame, text='lock_with_ink_pen Generate lock_with_ink_pen', bg='#4065A4', font=('Helvetica', 20), fg='white',
command=password_gene)
clic_ok.pack(fill=X)

packer sub_frame

sub_frame.grid(row=0, column=1, sticky=W)

Affiche la boite

frame.pack(expand=YES)

window.mainloop()

Salut voici mon code : (et merci pour tes videos Graven ;) )

`import os
import random
from tkinter import *

def generator_meals():
with open("Repas", "r+") as file:
repas = file.readlines()
repas_choice = random.choice(repas)
meals_entry.delete(0, END)
meals_entry.insert(0, repas_choice)
file.close

window = Tk()
window.title("Générateur de repas")
window.geometry("700x600")
window.iconbitmap("Lolo.ico")
window.config(background='#202255')

frame = Frame(window, bg='#202255')

right_frame = Frame(frame, bg='#202255')

title = Label(right_frame, text="Bienvenue dans votre générateur de repas !", font=("Courrier", 25), bg='#202255', fg='White')
title.pack()

sub_title = Label(right_frame, text="Qu'allez vous manger aujourd'hui...", font=("Courrier", 15), bg='#202255', fg='White')
sub_title.pack()

meals_entry = Entry(right_frame, font=("Helvetica", 20), bg='#4065A4', fg='white')
meals_entry.pack()

button_generator = Button(right_frame, text="Générer un repas", font=("Courrier", 15), bg='white', fg='#202255', command=generator_meals)
button_generator.pack(pady=25, fill=X)

right_frame.grid(row=0, column=1, sticky=W)

frame.pack(expand=YES)

window.mainloop()`

bonjour Graven ... trop bien tes TP ... merci pour tout ce partage .

import string
from random import randint, choice
from tkinter import *
#generateur de mots de passe aléatoires
def generateur():
    global password
    long_min = 8
    long_max = 12
    caractere = string.ascii_letters + string.digits + string.punctuation
    password = "".join(choice(caractere) for x in range(randint(long_min, long_max)))
    champ.delete(0, END)
    champ.insert(0, password)

#sauver le mot de passe dans un fichier .txt
def sauver():
    with open('password.txt', 'a+') as fichier:
        fichier.write(password +'\n')
        fichier.close()


#creer une fenetre
fenetre = Tk()
fenetre.title('mot de passe')
fenetre.geometry('600x400')
fenetre.iconbitmap('logo.ico')
fenetre.config(background='black')

#creer une frame
frame = Frame(fenetre, bg='black')

#creer une image
largeur = 300
hauteur = 300
image = PhotoImage(file=("image mot de passe.png")).zoom(35).subsample(32)
canvas = Canvas(frame, width=largeur, height=hauteur, bg='black', bd=0, highlightthickness=0)
canvas.create_image(hauteur/2, largeur/2, image=image)
canvas.grid(row=0, column=0, padx=20)

#creer une sous frame
frame_droite = Frame(frame, bg='black')

#creer un titre
titre = Label(frame_droite, text='Mot de passe', font='Arial', bg='black', fg='yellow')
titre.pack()

#creer un champ/entrée/input
champ = Entry(frame_droite, font='Arial', bg='black', fg='blue')
champ.pack()

#creer un bouton
bouton = Button(frame_droite, text='Générer', font='Arial', bg='black', fg='yellow', command=generateur)
bouton.pack(fill=X)

bouton = Button(frame_droite, text='Sauver', font='Arial', bg='black', fg='yellow', command=sauver)
bouton.pack(fill=X)

#titre a droite
frame_droite.grid(row=0, column=1, sticky=W)

#afficher la frame
frame.pack(expand=YES)

#creation d'une barre de menu
menu_bar = Menu(fenetre)
#creer un menu
file_menu = Menu(menu_bar, tearoff=0)
file_menu.add_command(label='Nouveau', command=generateur)
file_menu.add_command(label='Sauver', command=sauver)
file_menu.add_command(label='Quitter', command=fenetre.quit)
menu_bar.add_cascade(label='Fichier', menu=file_menu)
#ajouter le menu ds la fenetre
fenetre.config(menu=menu_bar)

#afficher la fenetre
fenetre.mainloop()

résultat

mot de passe
image
image réalisée avec Paint 3D sous Windows 10

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK