啊······没多久又见面了
有人可能会问为啥不发0.2而是直接发0.3
那我就解释下
0.2写好以后我又想到一些可以加上的功能,
但是网上有文档规定:
一个版本发布就不能再修改了。
所以就一次更新了两个版本······
0.2版本的代码我还是会放在文末
那么话不多说,直接把代码放上来吧
扫一扫PC版 V0.3 代码
import numpy as np
from PIL import Image
from pyzbar import pyzbar
import tkinter as tk
import tkinter.ttk as ttk
import tkinter.filedialog as filebox
import webbrowser
def readqr(imgpath):
# 读取文件,转成数组
im = np.array(Image.open(imgpath))
print(pyzbar.decode(im))
# 返回的信息还是很多的
"""
[
Decoded(data=b'http://www.bilibili.com',
type='QRCODE',
rect=Rect(left=35, top=35, width=263, height=264),
polygon=[Point(x=35, y=35), Point(x=35, y=297), Point(x=297, y=299), Point(x=298, y=35)])
]
"""
# 拿到内容
data = pyzbar.decode(im)[0].data.decode("utf-8") # http://www.bilibili.com
print(data)
return data
def openqr():
paths = filebox.askopenfilenames(title='打开图片')
print(paths)
return paths
def get_data():
global done
done = 0
data_text.configure(state='normal')
data_text.delete('0.0', tk.END)
data_text.insert(tk.END, '请在新窗口内操作' + '
')
paths = openqr()
data_text.delete('0.0', tk.END)
data_text.configure(state='disabled')
i = 0
for path in paths:
win.update()
data_text.configure(state='normal')
data_text.insert(tk.END, '请稍候,正在读取数据······' + '')
data_text.configure(state='disabled')
win.update()
try:
qrdata = readqr(path)
except:
qrdata = '无效的二维码图片!'
data_text.configure(state='normal')
line = len(data_text.get('0.0', tk.END).split('
')) - 1
print(line)
data_text.delete(str(line) + ".0", tk.END)
data_text.insert(tk.END, qrdata + '
')
data_text.insert(tk.END, '
')
data_text.configure(state='disabled')
i += 1
done = i / len(paths) * 100
pb['value'] = done
win.update()
def open_url():
urls = data_text.get('0.0', tk.END)
url_lst = urls.split('
')
for url in url_lst:
if url == '无效的二维码图片!':
webbrowser.open("http://rgzz.great-site.net/soft/scan/qr_error/")
else:
webbrowser.open(url)
# 创建窗口
win = tk.Tk()
win.title('扫一扫PC版 V0.2')
# 选择图片按钮
ttk.Button(win, text='选择图片', command=get_data).pack(padx=5, pady=5, fill=tk.X)
data_part = ttk.LabelFrame(win, text='二维码数据')
# 功能区
data_buttons = ttk.LabelFrame(win, text='操作中心')
ttk.Button(data_buttons, text='使用浏览器打开全部', command=open_url).pack(fill=tk.X, padx=5, pady=5)
data_buttons.pack(fill=tk.X, padx=5, pady=5)
# 显示二维码数据的地方
data_part.pack(fill=tk.BOTH, padx=5, pady=5)
data_text = tk.Text(data_part)
data_text.configure(state='disabled')
data_text.pack(fill=tk.BOTH, padx=5, pady=5)
# 进度条
done = 0
pb = ttk.Progressbar(win)
pb.pack(fill=tk.X, side=tk.BOTTOM)
win.mainloop()
能感受到代码量正在逐渐增加吗?
那么看完这代码多多的0.3,我们还是回去看看0.2吧······
扫一扫PC版 V0.2 代码
import numpy as np
from PIL import Image
from pyzbar import pyzbar
import tkinter as tk
import tkinter.ttk as ttk
import tkinter.filedialog as filebox
import webbrowser
def readqr(imgpath):
# 读取文件,转成数组
im = np.array(Image.open(imgpath))
print(pyzbar.decode(im))
# 返回的信息还是很多的
"""
[
Decoded(data=b'http://www.bilibili.com',
type='QRCODE',
rect=Rect(left=35, top=35, width=263, height=264),
polygon=[Point(x=35, y=35), Point(x=35, y=297), Point(x=297, y=299), Point(x=298, y=35)])
]
"""
# 拿到内容
data = pyzbar.decode(im)[0].data.decode("utf-8") # http://www.bilibili.com
print(data)
return data
def openqr():
paths = filebox.askopenfilenames(title='打开图片')
print(paths)
return paths
def get_data():
data_text.configure(state='normal')
data_text.insert(tk.END, '请在新窗口内操作' + '
')
data_text.configure(state='disabled')
paths = openqr()
data_text.delete('0.0', tk.END)
for path in paths:
try:
qrdata = readqr(path)
except:
qrdata = '无效的二维码图片!'
data_text.configure(state='normal')
data_text.insert(tk.END, qrdata + '
')
data_text.configure(state='disabled')
def open_url():
urls = data_text.get('0.0', tk.END)
url_lst = urls.split('
')
for url in url_lst:
webbrowser.open(url)
# 创建窗口
win = tk.Tk()
win.title('扫一扫PC版 V0.2')
# 选择图片按钮
ttk.Button(win, text='选择图片', command=get_data).pack(padx=5, pady=5, fill=tk.X)
data_part = ttk.LabelFrame(win, text='二维码数据')
# 功能区
data_buttons = ttk.LabelFrame(win, text='操作中心')
ttk.Button(data_buttons, text='使用浏览器打开全部', command=open_url).pack(fill=tk.X, padx=5, pady=5)
data_buttons.pack(fill=tk.X, padx=5, pady=5)
# 显示二维码数据的地方
data_part.pack(fill=tk.BOTH, padx=5, pady=5)
data_text = tk.Text(data_part)
data_text.configure(state='disabled')
data_text.pack(fill=tk.BOTH, padx=5, pady=5)
win.mainloop()
那么这就是本文的全部内容了,这次底下真没彩蛋
没彩蛋,但不代表没白字