QRCG/main.py
sairate 57420fd030 feat: 创建 QRCodeGenerator 项目
- 新增主程序文件 main.py 实现二维码生成功能
- 添加安装环境脚本 安装环境.py 以安装所需第三方库
- 创建 .idea 目录及相关配置文件,设置项目环境和忽略项
2025-05-24 17:06:00 +08:00

39 lines
1.2 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 编程前,运行【安装第三方库.py】文件安装本课用到的第三方库
import tkinter
from PIL import Image, ImageTk
from tkinter import filedialog
import os
from amzqr import amzqr
w = tkinter.Tk()
w.geometry("400x400")
w.resizable(0,0)
bg_image = Image.open("qrcode_bg.png")
bg_image = ImageTk.PhotoImage(bg_image)
bg_label = tkinter.Label(w, image=bg_image)
bg_label.pack()
t1 = tkinter.Text(w, font=("微软雅黑", 12),width=30,height=5)
t1.place(x=80, y=100)
t2 = tkinter.Text(w, font=("微软雅黑", 12),width=23,height=1)
t2.place(x=80, y=250)
def get_pic():
pic_path = filedialog.askopenfilename()
t2.delete("1.0", "end")
t2.insert("1.0", pic_path)
btn1 = tkinter.Button(w, text="浏览", font=("微软雅黑", 12), command=get_pic)
btn1.place(x=312, y=250, height=25)
def qr():
words = t1.get("1.0","end")
words = "".join(words.split('\n'))
picture = t2.get("1.0", "end")[:-1]
version, level, qr_name = amzqr.run(words=words, picture=picture, colorized=True)
os.system(qr_name)
btn2 = tkinter.Button(w, text="生成二维码", font=("微软雅黑", 15), command=qr)
btn2.place(x=80, y=300, width=250)
w.mainloop()