Valider 28953c07 rédigé par Thorfin89's avatar Thorfin89
Parcourir les fichiers

First commit

parent
Chargement en cours
Chargement en cours
Chargement en cours
Chargement en cours

main.py

0 → 100644
+122 −0
Numéro de ligne d'origine Ligne d'origine Numéro de ligne de diff Ligne de diff
from tkinter import *
import qrcode
from qrcode.constants import ERROR_CORRECT_M
from PIL import Image

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

def new_file():
    pass


def sel():
    selection = str(value.get())
    label.config(text=selection)


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

        logo = PhotoImage(file="qrcode.png")
        logovisu.config(image=logo)

        img = Image.open("qrcode.png")
        size = img.size
        print(size)
        logovisu.place(x=200 - size[0] // 2, y=200 - size[1] // 2)
    else:
        print("Pas de texte à coder")


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

ESP = 25

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

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

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

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

# ===== FRAMES =====
conf = Frame(root, bg="lightgray")
conf.place(x=0, y=0, width=400, height=400)

visu = Frame(root, bg="gray")
visu.place(x=401, y=0, width=400, height=400)

saisie = Frame(root, bg="lightgray")
saisie.place(x=0, y=401, width=800, height=240)

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

# boutons radios de choix
value = StringVar()
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)

# affichage du choix
label = Label(conf, text="OUI", width=20, height=2, borderwidth=1, relief="solid")
label.config(bg="lightgray")
label.place(x=10, y=10 + 5 * ESP)

# bouton de création du QRCode
create_Btn = Button(conf, text="Créer le Code", bg="lightgreen", command=create_code)
create_Btn.place(x=280, y=360, width=100, height=40)

# texte à coder
labelTexte = Label(saisie, text='Texte à coder :', bg="lightgray")
labelTexte.place(x=10, y=10)
texte = Entry(saisie, width=122)
texte.place(x=30, y=40)

# affichage du QRcode
logo = ""
logovisu = Label(visu)
logovisu.config(image=logo)
logovisu.place(x=400, y=400)

root.mainloop()