Chargement en cours main.py +55 −31 Numéro de ligne d'origine Ligne d'origine Numéro de ligne de diff Ligne de diff Chargement en cours @@ -11,23 +11,19 @@ from PIL import Image COLOR = "#000000" COLOR = "#000000" VERSION = 3 VERSION = 3 BOXE_SIZE = 5 BOXE_SIZE = 2 BORDER = 1 BORDER = 1 # ===== FONCTIONS ===== # ===== FONCTIONS ===== def new_file(): pass def color_selection(): def color_selection(): global COLOR selection = str(color.get()) selection = str(color.get()) print(str(selection)) COLOR = selection color_label.config(text=selection) def create_qrcode(): def create_qrcode(): if texte.get() != "": if texte_a_coder.get() != "": global qrcode_img global qrcode_img qr = qrcode.QRCode( qr = qrcode.QRCode( version=VERSION, version=VERSION, Chargement en cours @@ -35,18 +31,18 @@ def create_qrcode(): box_size=BOXE_SIZE, box_size=BOXE_SIZE, border=BORDER border=BORDER ) ) qr.add_data(texte.get()) qr.add_data(texte_a_coder.get()) qr.make(fit='True') qr.make(fit='True') # création et sauvegarde de l'image du QRCode img = qr.make_image(fill_color=COLOR, back_color="white") img = qr.make_image(fill_color=COLOR, back_color="white") img.save('qrcode.png') img.save('qrcode.png') # affichage du QRCode qrcode_img = PhotoImage(file="qrcode.png") qrcode_img = PhotoImage(file="qrcode.png") qrcode_frame.config(image=qrcode_img, bg="white") qrcode_frame.config(image=qrcode_img, bg="white") # calcul de la taille du QRCode pour le centrer dans la fenêtre img = Image.open("qrcode.png") img = Image.open("qrcode.png") size = img.size size = img.size qrcode_frame.place(x=198 - size[0] // 2, y=198 - size[1] // 2) qrcode_frame.place(x=198 - size[0] // 2, y=198 - size[1] // 2) # centrage else: else: messagebox.showerror("Erreur", "Il n'y a pas de données à coder") messagebox.showerror("Erreur", "Il n'y a pas de données à coder") Chargement en cours @@ -57,8 +53,6 @@ root.geometry('800x480+100+100') root.title("ObjQRCode") root.title("ObjQRCode") root.config(bg="#CCCCCC") root.config(bg="#CCCCCC") ESP = 25 # Création de la barre de menus # Création de la barre de menus menu_general = Menu(root) menu_general = Menu(root) Chargement en cours @@ -66,7 +60,7 @@ menu_general = Menu(root) menu_fichier = Menu(menu_general, tearoff=0) menu_fichier = Menu(menu_general, tearoff=0) menu_general.add_cascade(label="Fichier", menu=menu_fichier) menu_general.add_cascade(label="Fichier", menu=menu_fichier) # Création des sous menus 'Fichiers' # Création des sous menus 'Fichiers' menu_fichier.add_command(label="Nouveau", command=new_file) menu_fichier.add_command(label="Nouveau") menu_fichier.add_command(label="Ouvrir") menu_fichier.add_command(label="Ouvrir") menu_fichier.add_command(label="Enregistrer") menu_fichier.add_command(label="Enregistrer") menu_fichier.add_command(label="Enregistrer sous") menu_fichier.add_command(label="Enregistrer sous") Chargement en cours Chargement en cours @@ -94,31 +88,61 @@ bottom_frame.place(x=0, y=421, width=800, height=220) # ===== WIDGETS ===== # ===== WIDGETS ===== # Choix de la couleur # Choix de la couleur titre = Label(left_frame, text="Couleur du QRCode :", bg="#CCCCCC") titre.place(x=10, y=20) # boutons radios de choix color = StringVar() color = StringVar() color.set(COLOR) color.set(COLOR) black_btn = Radiobutton(left_frame, bg="#CCCCCC", text="Noir", variable=color, value="#000000", command=color_selection) titre = Label(left_frame, text="Couleur du QRCode :", bg="#CCCCCC") blue_btn = Radiobutton(left_frame, bg="#CCCCCC", text="Bleu", variable=color, value="#0000FF", command=color_selection) titre.place(x=10, y=20) red_btn = Radiobutton(left_frame, bg="#CCCCCC", text="Rouge", variable=color, value="#FF0000", command=color_selection) black_btn = Radiobutton(left_frame, bg="#CCCCCC", text="Noir", variable=color, value="#000000", command=color_selection) blue_btn = Radiobutton(left_frame, bg="#CCCCCC", text="Bleu", variable=color, value="#0000FF", command=color_selection) red_btn = Radiobutton(left_frame, bg="#CCCCCC", text="Rouge", variable=color, value="#FF0000", command=color_selection) green_btn = Radiobutton(left_frame, bg="#CCCCCC", text="Vert", variable=color, value="#00FF00", command=color_selection) violet_btn = Radiobutton(left_frame, bg="#CCCCCC", text="Violet", variable=color, value="#800080", command=color_selection) orange_btn = Radiobutton(left_frame, bg="#CCCCCC", text="Orange", variable=color, value="#FFA500", command=color_selection) brown_btn = Radiobutton(left_frame, bg="#CCCCCC", text="Marron", variable=color, value="#6C5417", command=color_selection) ESP = 25 # espace entre les boutons radios black_btn.place(x=10, y=20 + ESP) black_btn.place(x=10, y=20 + ESP) blue_btn.place(x=10, y=20 + 2 * ESP) blue_btn.place(x=10, y=20 + 2 * ESP) red_btn.place(x=10, y=20 + 3 * ESP) red_btn.place(x=10, y=20 + 3 * ESP) # affichage de la couleur choisie green_btn.place(x=10, y=20 + 4 * ESP) color_label = Label(left_frame, text="#000000", width=20, height=2, borderwidth=1, relief="solid") violet_btn.place(x=10, y=20 + 5 * ESP) color_label.config(bg="#CCCCCC") orange_btn.place(x=10, y=20 + 6 * ESP) color_label.place(x=10, y=10 + 5 * ESP) brown_btn.place(x=10, y=20 + 7 * ESP) # choix de la BOXE_SIZE BoxS = IntVar() boxe_size_scale = Scale(left_frame, from_=1, to=10, variable=BoxS, orient=HORIZONTAL) boxe_size_scale.config(bg="#CCCCCC", label="Taille des points :", length=180, highlightthickness=0) boxe_size_scale.set(5) boxe_size_scale.place(x=180, y=18) # choix de la taille de la bordure BorS = IntVar() boxe_size_scale = Scale(left_frame, from_=1, to=10, variable=BorS, orient=HORIZONTAL) boxe_size_scale.config(bg="#CCCCCC", label="Épaisseur de la bordure :", length=180, highlightthickness=0) boxe_size_scale.set(2) boxe_size_scale.place(x=180, y=100) # bouton de création du QRCode # bouton de création du QRCode create_Btn = Button(left_frame, text="Créer le Code", bg="#CCCCCC", command=create_qrcode) create_Btn = Button(left_frame, text="Créer le Code", bg="#88FF88", command=create_qrcode) create_Btn.place(x=260, y=360, width=100, height=40) create_Btn.place(x=260, y=360, width=100, height=40) # texte à coder # texte à coder texte_a_coder = Label(bottom_frame, text='Données à coder :', bg="#CCCCCC") titre_texte_a_coder = Label(bottom_frame, text='Données à coder :', bg="#CCCCCC") texte_a_coder.place(x=10, y=0) titre_texte_a_coder.place(x=10, y=0) texte = Entry(bottom_frame, width=122) texte_a_coder = Entry(bottom_frame, width=122) texte.place(x=30, y=28) texte_a_coder.insert(0, "https://objnux.fr") texte_a_coder.place(x=30, y=25) # affichage du QRcode # affichage du QRcode qrcode_img = "" qrcode_img = "" Chargement en cours Chargement en cours
main.py +55 −31 Numéro de ligne d'origine Ligne d'origine Numéro de ligne de diff Ligne de diff Chargement en cours @@ -11,23 +11,19 @@ from PIL import Image COLOR = "#000000" COLOR = "#000000" VERSION = 3 VERSION = 3 BOXE_SIZE = 5 BOXE_SIZE = 2 BORDER = 1 BORDER = 1 # ===== FONCTIONS ===== # ===== FONCTIONS ===== def new_file(): pass def color_selection(): def color_selection(): global COLOR selection = str(color.get()) selection = str(color.get()) print(str(selection)) COLOR = selection color_label.config(text=selection) def create_qrcode(): def create_qrcode(): if texte.get() != "": if texte_a_coder.get() != "": global qrcode_img global qrcode_img qr = qrcode.QRCode( qr = qrcode.QRCode( version=VERSION, version=VERSION, Chargement en cours @@ -35,18 +31,18 @@ def create_qrcode(): box_size=BOXE_SIZE, box_size=BOXE_SIZE, border=BORDER border=BORDER ) ) qr.add_data(texte.get()) qr.add_data(texte_a_coder.get()) qr.make(fit='True') qr.make(fit='True') # création et sauvegarde de l'image du QRCode img = qr.make_image(fill_color=COLOR, back_color="white") img = qr.make_image(fill_color=COLOR, back_color="white") img.save('qrcode.png') img.save('qrcode.png') # affichage du QRCode qrcode_img = PhotoImage(file="qrcode.png") qrcode_img = PhotoImage(file="qrcode.png") qrcode_frame.config(image=qrcode_img, bg="white") qrcode_frame.config(image=qrcode_img, bg="white") # calcul de la taille du QRCode pour le centrer dans la fenêtre img = Image.open("qrcode.png") img = Image.open("qrcode.png") size = img.size size = img.size qrcode_frame.place(x=198 - size[0] // 2, y=198 - size[1] // 2) qrcode_frame.place(x=198 - size[0] // 2, y=198 - size[1] // 2) # centrage else: else: messagebox.showerror("Erreur", "Il n'y a pas de données à coder") messagebox.showerror("Erreur", "Il n'y a pas de données à coder") Chargement en cours @@ -57,8 +53,6 @@ root.geometry('800x480+100+100') root.title("ObjQRCode") root.title("ObjQRCode") root.config(bg="#CCCCCC") root.config(bg="#CCCCCC") ESP = 25 # Création de la barre de menus # Création de la barre de menus menu_general = Menu(root) menu_general = Menu(root) Chargement en cours @@ -66,7 +60,7 @@ menu_general = Menu(root) menu_fichier = Menu(menu_general, tearoff=0) menu_fichier = Menu(menu_general, tearoff=0) menu_general.add_cascade(label="Fichier", menu=menu_fichier) menu_general.add_cascade(label="Fichier", menu=menu_fichier) # Création des sous menus 'Fichiers' # Création des sous menus 'Fichiers' menu_fichier.add_command(label="Nouveau", command=new_file) menu_fichier.add_command(label="Nouveau") menu_fichier.add_command(label="Ouvrir") menu_fichier.add_command(label="Ouvrir") menu_fichier.add_command(label="Enregistrer") menu_fichier.add_command(label="Enregistrer") menu_fichier.add_command(label="Enregistrer sous") menu_fichier.add_command(label="Enregistrer sous") Chargement en cours Chargement en cours @@ -94,31 +88,61 @@ bottom_frame.place(x=0, y=421, width=800, height=220) # ===== WIDGETS ===== # ===== WIDGETS ===== # Choix de la couleur # Choix de la couleur titre = Label(left_frame, text="Couleur du QRCode :", bg="#CCCCCC") titre.place(x=10, y=20) # boutons radios de choix color = StringVar() color = StringVar() color.set(COLOR) color.set(COLOR) black_btn = Radiobutton(left_frame, bg="#CCCCCC", text="Noir", variable=color, value="#000000", command=color_selection) titre = Label(left_frame, text="Couleur du QRCode :", bg="#CCCCCC") blue_btn = Radiobutton(left_frame, bg="#CCCCCC", text="Bleu", variable=color, value="#0000FF", command=color_selection) titre.place(x=10, y=20) red_btn = Radiobutton(left_frame, bg="#CCCCCC", text="Rouge", variable=color, value="#FF0000", command=color_selection) black_btn = Radiobutton(left_frame, bg="#CCCCCC", text="Noir", variable=color, value="#000000", command=color_selection) blue_btn = Radiobutton(left_frame, bg="#CCCCCC", text="Bleu", variable=color, value="#0000FF", command=color_selection) red_btn = Radiobutton(left_frame, bg="#CCCCCC", text="Rouge", variable=color, value="#FF0000", command=color_selection) green_btn = Radiobutton(left_frame, bg="#CCCCCC", text="Vert", variable=color, value="#00FF00", command=color_selection) violet_btn = Radiobutton(left_frame, bg="#CCCCCC", text="Violet", variable=color, value="#800080", command=color_selection) orange_btn = Radiobutton(left_frame, bg="#CCCCCC", text="Orange", variable=color, value="#FFA500", command=color_selection) brown_btn = Radiobutton(left_frame, bg="#CCCCCC", text="Marron", variable=color, value="#6C5417", command=color_selection) ESP = 25 # espace entre les boutons radios black_btn.place(x=10, y=20 + ESP) black_btn.place(x=10, y=20 + ESP) blue_btn.place(x=10, y=20 + 2 * ESP) blue_btn.place(x=10, y=20 + 2 * ESP) red_btn.place(x=10, y=20 + 3 * ESP) red_btn.place(x=10, y=20 + 3 * ESP) # affichage de la couleur choisie green_btn.place(x=10, y=20 + 4 * ESP) color_label = Label(left_frame, text="#000000", width=20, height=2, borderwidth=1, relief="solid") violet_btn.place(x=10, y=20 + 5 * ESP) color_label.config(bg="#CCCCCC") orange_btn.place(x=10, y=20 + 6 * ESP) color_label.place(x=10, y=10 + 5 * ESP) brown_btn.place(x=10, y=20 + 7 * ESP) # choix de la BOXE_SIZE BoxS = IntVar() boxe_size_scale = Scale(left_frame, from_=1, to=10, variable=BoxS, orient=HORIZONTAL) boxe_size_scale.config(bg="#CCCCCC", label="Taille des points :", length=180, highlightthickness=0) boxe_size_scale.set(5) boxe_size_scale.place(x=180, y=18) # choix de la taille de la bordure BorS = IntVar() boxe_size_scale = Scale(left_frame, from_=1, to=10, variable=BorS, orient=HORIZONTAL) boxe_size_scale.config(bg="#CCCCCC", label="Épaisseur de la bordure :", length=180, highlightthickness=0) boxe_size_scale.set(2) boxe_size_scale.place(x=180, y=100) # bouton de création du QRCode # bouton de création du QRCode create_Btn = Button(left_frame, text="Créer le Code", bg="#CCCCCC", command=create_qrcode) create_Btn = Button(left_frame, text="Créer le Code", bg="#88FF88", command=create_qrcode) create_Btn.place(x=260, y=360, width=100, height=40) create_Btn.place(x=260, y=360, width=100, height=40) # texte à coder # texte à coder texte_a_coder = Label(bottom_frame, text='Données à coder :', bg="#CCCCCC") titre_texte_a_coder = Label(bottom_frame, text='Données à coder :', bg="#CCCCCC") texte_a_coder.place(x=10, y=0) titre_texte_a_coder.place(x=10, y=0) texte = Entry(bottom_frame, width=122) texte_a_coder = Entry(bottom_frame, width=122) texte.place(x=30, y=28) texte_a_coder.insert(0, "https://objnux.fr") texte_a_coder.place(x=30, y=25) # affichage du QRcode # affichage du QRcode qrcode_img = "" qrcode_img = "" Chargement en cours