Valider 80f87d1d rédigé par Thorfin89's avatar Thorfin89
Parcourir les fichiers

Renommage des variables. Nettoyage du code

parent a4afe82e
Chargement en cours
Chargement en cours
Chargement en cours
Chargement en cours
+70 −78
Numéro de ligne d'origine Ligne d'origine Numéro de ligne de diff Ligne de diff
@@ -3,135 +3,127 @@
# Projet initié le 24/12/2023
# Projet initié le 24/12/2023


from tkinter import *
from tkinter import *
from tkinter import messagebox
import qrcode
import qrcode


from qrcode.constants import ERROR_CORRECT_M
from qrcode.constants import ERROR_CORRECT_M
from PIL import Image
from PIL import Image


COLOR = "#000000"
VERSION = 3
BOXE_SIZE = 5
BORDER = 1


# ===== FONCTIONS =====


# ===== FONCTIONS =====
def new_file():
def new_file():
    pass
    pass




def sel():
def color_selection():
    selection = str(value.get())
    selection = str(color.get())
    label.config(text=selection)
    print(str(selection))
    color_label.config(text=selection)




def create_code():
def create_qrcode():
    if texte.get() != "":
    if texte.get() != "":
        erreur("")
        global qrcode_img
        global logo
        qr = qrcode.QRCode(
        qr = qrcode.QRCode(
            version=3,
            version=VERSION,
            error_correction=ERROR_CORRECT_M,
            error_correction=ERROR_CORRECT_M,
            box_size=5,
            box_size=BOXE_SIZE,
            border=2
            border=BORDER
        )
        )
        qr.add_data(texte.get())
        qr.add_data(texte.get())
        qr.make(fit='True')
        qr.make(fit='True')
        img = qr.make_image(fill_color="blue", back_color="white")

        img = qr.make_image(fill_color=COLOR, back_color="white")
        img.save('qrcode.png')
        img.save('qrcode.png')


        logo = PhotoImage(file="qrcode.png")
        qrcode_img = PhotoImage(file="qrcode.png")
        logovisu.config(image=logo, bg="white")
        qrcode_frame.config(image=qrcode_img, bg="white")


        img = Image.open("qrcode.png")
        img = Image.open("qrcode.png")
        size = img.size
        size = img.size
        logovisu.place(x=200 - size[0] // 2, y=200 - size[1] // 2)
        qrcode_frame.place(x=198 - size[0] // 2, y=198 - size[1] // 2)
    else:
        erreur("Il n'y a pas de données à coder")


def erreur(message):
    error_label = Label(saisie)
    if message != "":
        error_label.config(bg="lightgray", fg="red", text=message)
    else:
    else:
        error_label.config(bg="lightgray", fg="lightgray", text="======================================")
        messagebox.showerror("Erreur", "Il n'y a pas de données à coder")
    error_label.place(x=390, y=10)




# création de la fenêtre principale
# création de la fenêtre principale
root = Tk()
root = Tk()
root.geometry('800x480+100+100')
root.geometry('800x480+100+100')
root.title("ObjQRCode")
root.title("ObjQRCode")
root.config(bg="lightgray")
root.config(bg="#CCCCCC")


ESP = 25
ESP = 25


# Création de la barre des menus
# Création de la barre de menus
menuBar = Menu(root)
menu_general = Menu(root)


# Création du menu principal 'Fichier'
# Création du menu principal 'Fichier'
menuFichier = Menu(menuBar, tearoff=0)
menu_fichier = Menu(menu_general, tearoff=0)
menuBar.add_cascade(label="Fichier", menu=menuFichier)
menu_general.add_cascade(label="Fichier", menu=menu_fichier)
# Création des sous menus :
# Création des sous menus 'Fichiers'
menuFichier.add_command(label="Nouveau", command=new_file)
menu_fichier.add_command(label="Nouveau", command=new_file)
menuFichier.add_command(label="Ouvrir")
menu_fichier.add_command(label="Ouvrir")
menuFichier.add_command(label="Enregistrer")
menu_fichier.add_command(label="Enregistrer")
menuFichier.add_command(label="Enregistrer sous")
menu_fichier.add_command(label="Enregistrer sous")
menuFichier.add_command(label="Quitter", command=quit)
menu_fichier.add_command(label="Quitter", command=quit)


# Création du menu principal 'Fichier'
# Création du menu principal 'Aide'
menuAide = Menu(menuBar, tearoff=0)
menu_aide = Menu(menu_general, tearoff=0)
menuBar.add_cascade(label="Aide", menu=menuAide)
menu_general.add_cascade(label="Aide", menu=menu_aide)
# Création des sous menus :
# Création des sous menus 'Aide'
menuAide.add_command(label="Info")
menu_aide.add_command(label="Info")


# Configuration de la barre des menus
# Configuration de la barre des menus
root.config(menu=menuBar)
root.config(menu=menu_general)


# ===== FRAMES =====
# ===== FRAMES =====
conf = Frame(root, bg="lightgray")
left_frame = Frame(root, bg="#CCCCCC")  # cadre de gauche : configuration
conf.place(x=0, y=0, width=380, height=400)
left_frame.place(x=0, y=0, width=380, height=420)


visu = Frame(root, bg="gray")
right_frame = Frame(root, bg="gray")  # cadre de droite : affichage du qrcode
visu.place(x=380, y=20, width=400, height=400)
right_frame.place(x=380, y=20, width=400, height=400)


saisie = Frame(root, bg="lightgray")
bottom_frame = Frame(root, bg="#CCCCCC")  # cadre du bas : saisie des données à coder
saisie.place(x=0, y=401, width=800, height=240)
bottom_frame.place(x=0, y=421, width=800, height=220)


# ===== WIDGETS =====
# ===== WIDGETS =====


# boutons radios de choix
# Choix de la couleur
value = StringVar()
titre = Label(left_frame, text="Couleur du QRCode :", bg="#CCCCCC")
value.set("OUI")
bouton1 = Radiobutton(conf, text="Oui", variable=value, value="OUI", command=sel)
bouton2 = Radiobutton(conf, text="Non", variable=value, value="NON", command=sel)
bouton3 = Radiobutton(conf, text="Peut-être", variable=value, value="JE NE SAIS PAS", command=sel)
bouton1.config(bg="lightgray")
bouton2.config(bg="lightgray")
bouton3.config(bg="lightgray")
bouton1.place(x=10, y=20 + ESP)
bouton2.place(x=10, y=20 + 2 * ESP)
bouton3.place(x=10, y=20 + 3 * ESP)

# titre de la zone de choix
titre = Label(conf, text="CHOIX :", bg="lightgray")
titre.place(x=10, y=20)
titre.place(x=10, y=20)

# boutons radios de choix
# affichage du choix
color = StringVar()
label = Label(conf, text="OUI", width=20, height=2, borderwidth=1, relief="solid")
color.set(COLOR)
label.config(bg="lightgray")

label.place(x=10, y=10 + 5 * ESP)
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)
black_btn.place(x=10, y=20 + ESP)
blue_btn.place(x=10, y=20 + 2 * ESP)
red_btn.place(x=10, y=20 + 3 * ESP)
# affichage de la couleur choisie
color_label = Label(left_frame, text="#000000", width=20, height=2, borderwidth=1, relief="solid")
color_label.config(bg="#CCCCCC")
color_label.place(x=10, y=10 + 5 * ESP)
# bouton de création du QRCode
# bouton de création du QRCode
create_Btn = Button(conf, text="Créer le Code", bg="lightgreen", command=create_code)
create_Btn = Button(left_frame, text="Créer le Code", bg="#CCCCCC", 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
labelTexte = Label(saisie, text='Données à coder :', bg="lightgray")
texte_a_coder = Label(bottom_frame, text='Données à coder :', bg="#CCCCCC")
labelTexte.place(x=10, y=10)
texte_a_coder.place(x=10, y=0)
texte = Entry(saisie, width=122)
texte = Entry(bottom_frame, width=122)
texte.place(x=30, y=40)
texte.place(x=30, y=28)


# affichage du QRcode
# affichage du QRcode
logo = ""
qrcode_img = ""
logovisu = Label(visu)
qrcode_frame = Label(right_frame)
logovisu.config(image=logo)
qrcode_frame.config(image=qrcode_img)
logovisu.place(x=400, y=400)
qrcode_frame.place(x=400, y=400)  # on place l'image par défaut hors champ


root.mainloop()
root.mainloop()