Add script to generate qr from clipboard
This commit is contained in:
parent
311eebaf0f
commit
21dbae764a
1 changed files with 54 additions and 0 deletions
54
prog/qr.py
Normal file
54
prog/qr.py
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
"""
|
||||||
|
QR Code creation from clipboard.
|
||||||
|
|
||||||
|
Test this program simply with pipx:
|
||||||
|
|
||||||
|
pipx run https://git.sekun.eu/sekun/utils/raw/branch/main/prog/qr.py
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# /// script
|
||||||
|
# dependencies = [
|
||||||
|
# "pyqrcode",
|
||||||
|
# ]
|
||||||
|
# ///
|
||||||
|
|
||||||
|
|
||||||
|
import tkinter as tk
|
||||||
|
from tkinter import messagebox
|
||||||
|
|
||||||
|
import pyqrcode as qr
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
|
||||||
|
root = tk.Tk()
|
||||||
|
root.title = "Qr code"
|
||||||
|
root.state("iconic")
|
||||||
|
data = root.clipboard_get()
|
||||||
|
try:
|
||||||
|
code = qr.create(data)
|
||||||
|
except ValueError as e:
|
||||||
|
messagebox.showerror(
|
||||||
|
"Qr code", f"Erreur lors de la création du code QR.\n«{e}»"
|
||||||
|
)
|
||||||
|
exit(1)
|
||||||
|
|
||||||
|
sw = root.winfo_screenwidth()
|
||||||
|
sh = root.winfo_screenheight()
|
||||||
|
size = min(sw, sh) - 100
|
||||||
|
|
||||||
|
scale = size // (len(code.code[0]) + 8)
|
||||||
|
img = tk.BitmapImage(data=code.xbm(scale=scale))
|
||||||
|
w = img.width()
|
||||||
|
root.geometry(f"{w}x{w}+50+50")
|
||||||
|
img.config(background="white")
|
||||||
|
label = tk.Label(root, image=img)
|
||||||
|
label.pack()
|
||||||
|
root.mainloop()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Loading…
Reference in a new issue