Commit 8cefbb44 authored by Thorfin89's avatar Thorfin89

Choix des couleurs sur deux touches.

Affichage des erreurs bugué
parent ebeb41e4
### objQRCode
# objQRCode
objQRCode est un utilitaire pour créer des QRCode écrit en python.
Utilitaire pour créer des QRCode écrit en python.
C'est en faite une interface graphique pour qrcode sous python.
Ce projet est au tout début de son développement.
Paquets à installer :
## Paquets à installer :
- qrcode
- pillow
## Sources :
### qrcode - python
- https://pypi.org/project/qrcode/
## similaires :
### segno - python
- https://segno.readthedocs.io/en/latest/index.html
- https://www.freecodecamp.org/news/how-to-create-stunning-qr-codes-with-python
......@@ -4,24 +4,45 @@
from tkinter import *
from tkinter import messagebox
import qrcode
from tkinter.colorchooser import askcolor
import qrcode
from qrcode.constants import ERROR_CORRECT_M
from PIL import Image
COLOR = "#000000"
fg_color = "#000000"
bg_color = "#FFFFFF"
VERSION = 3
# ===== FONCTIONS =====
def color_selection():
global COLOR
selection = str(color.get())
COLOR = selection
# choix de la couleur du fond
def set_bg_color():
global bg_color
(rgb, selection) = askcolor() # Appel de la boîte de dialogue 'Couleur'
if selection:
bg_color = selection
bg_color_btn.config(bg=bg_color)
if texte_a_coder != "":
create_qrcode()
# choix de la couleur du code
def set_fg_color():
global fg_color
(rgb, selection) = askcolor() # Appel de la boîte de dialogue 'Couleur'
if selection:
fg_color = selection
fg_color_btn.config(bg=fg_color)
if texte_a_coder:
print(texte_a_coder)
create_qrcode()
def create_qrcode():
if texte_a_coder.get() != "":
global qrcode_img
bs = boxe_size_scale.get()
......@@ -36,7 +57,7 @@ def create_qrcode():
qr.add_data(texte_a_coder.get())
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=fg_color, back_color=bg_color)
img.save('qrcode.png')
# affichage du QRCode
qrcode_img = PhotoImage(file="qrcode.png")
......@@ -45,8 +66,8 @@ def create_qrcode():
img = Image.open("qrcode.png")
size = img.size
qrcode_frame.place(x=198 - size[0] // 2, y=198 - size[1] // 2) # centrage
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")
# création de la fenêtre principale
......@@ -89,36 +110,13 @@ bottom_frame.place(x=0, y=421, width=800, height=220)
# ===== WIDGETS =====
# Choix de la couleur
color = StringVar()
color.set(COLOR)
titre = Label(left_frame, text="Couleur du QRCode :", bg="#CCCCCC")
titre.place(x=10, y=20)
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)
blue_btn.place(x=10, y=20 + 2 * ESP)
red_btn.place(x=10, y=20 + 3 * ESP)
green_btn.place(x=10, y=20 + 4 * ESP)
violet_btn.place(x=10, y=20 + 5 * ESP)
orange_btn.place(x=10, y=20 + 6 * ESP)
brown_btn.place(x=10, y=20 + 7 * ESP)
# Choix des couleurs
titre_choix_couleur = Label(left_frame, text="Choix de couleurs :", bg="#CCCCCC")
titre_choix_couleur.place(x=20, y=18)
bg_color_btn = Button(left_frame, bg=bg_color, relief=SUNKEN, command=set_bg_color)
bg_color_btn.place(x=82, y=62, width=20, height=20)
fg_color_btn = Button(left_frame, bg=fg_color, relief=SUNKEN, command=set_fg_color)
fg_color_btn.place(x=70, y=50, width=20, height=20)
# choix de la BOXE_SIZE
boxe_size = IntVar()
......@@ -142,7 +140,6 @@ create_Btn.place(x=260, y=360, width=100, height=40)
titre_texte_a_coder = Label(bottom_frame, text='Données à coder :', bg="#CCCCCC")
titre_texte_a_coder.place(x=10, y=0)
texte_a_coder = Entry(bottom_frame, width=122)
texte_a_coder.insert(0, "https://objnux.fr") # ligne à supprimer une fois le code validé
texte_a_coder.place(x=30, y=25)
# affichage du QRcode
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment