current position:Home>Python develops a color dynamic two-dimensional code generator in one hour, and uses the virtual environment to package and release the EXE program.
Python develops a color dynamic two-dimensional code generator in one hour, and uses the virtual environment to package and release the EXE program.
2022-02-02 00:53:05 【Lu Jacob】
Preface
Beginners Python I learned about this project when I was , It's amazing ! By calling MyQR The library realizes the synthesis of color two-dimensional codes . I won't introduce this library here , Those interested can search by themselves , There are many related detailed tutorials .
At first, I wanted to share it with my good friends , But I can't write a graphical interface , It has always been in my blog draft box , Today, I can finally write it and share it with you , Super happy !
The following code explanation is piecemeal , Finally, there is complete code . Including the virtual environment packaging and release at the end of the article EXE Program tutorial editing in graphite document , It's been said in great detail , I don't know. You can talk about me in private .
design sketch
Core function design
Support .png、.jpg、.gif、.bmp Format conversion , Choose your own materials and pictures .
UI Layout
The program requires few variables , common Three inputs :“ QR code analysis link ”、“ Material name ”、“ Finished product name ”, Because the input box for resolving links is long , So center layout , The rest “ Material name ”、“ Finished product name ” The input field of is short , So the left-right symmetrical layout , In this way, the whole presents “ symmetry 、 Standard Qi ” The effect of .
The material is divided into .png、.jpg、.gif、.bmp Format , use Checkbutton Check the part , Check according to your own material type ! The image generated in this way is also consistent with the material format type .
On this basis, the design is relatively simple , In addition to the beautification of color , I didn't insert some pictures to decorate , You can carry out secondary development on this basis .
On the design idea of graphical interface
The graphical interface I use is Python Self contained tkinter library , I don't think it's difficult to learn the graphical interface , When you are proficient , You'll find out , He is just one “ window + parts + function ” A process of , The window provides a good basis for our further design “ Containers ”, Components lay the foundation for the functions we realize “ Basics ”, The function is realized by the trigger of the button “ function ”.
Implementation steps ( One ): Start by building an interface
The interface is like a drawing board , With a drawing board, we can draw on it . besides , We also need to prepare some paint , Only in this way can the painting be colorful , And the interface also has a lot of decoration , For example, the title of the interface 、 Icon 、 These sizes .
from tkinter import *
import tkinter as tk
TOP6 = Tk()# Initialize a window
TOP6.geometry("575x375")# Set the size for this window
TOP6.iconbitmap(' Icon .ico')# Specify the window icon
TOP6.title(' Color dynamic QR code generator V1.0')# Give the window a name
TOP6.mainloop()# Window loop
Copy code
How to get .ico Format icons ?
stay use Python Write an office gadget for the girl you like , She said it was great ! In this post , We have explained .
First, choose your favorite picture , And then in Icon online conversion website It can be converted .
As long as the pictures are not too much, they are free .
Implementation steps ( Two ): Add features to the interface
according to UI Design we need four components : label ( Describe the data type )、 Input box ( Receive data )、Checkbutton Check the part ( Select the material format type )、 Button ( Trigger function ).
# QR code analysis link
label = StringVar()
input_name = Label(TOP6, text=' QR code analysis link ', font=(' Regular script ', 20)).place(x=175, y=20)
entry20 = Entry(TOP6, bg='#ffffff', width=30, textvariable=label, font=(' Regular script ', 20)).place(x=75, y=80)
# Material type options
var1 = StringVar()
var1.set("F")
c = tk.Checkbutton(TOP6, text=".jpg", variable=var1, onvalue="T", offvalue="F")
c.grid(row=30, column=0, sticky=W)
c.place(x=100, y=125)
var2 = StringVar()
var2.set("F")
c = tk.Checkbutton(TOP6, text=".png", variable=var2, onvalue="T", offvalue="F")
c.grid(row=30, column=0, sticky=W)
c.place(x=200, y=125)
var3 = StringVar()
var3.set("F")
c = tk.Checkbutton(TOP6, text=".gif", variable=var3, onvalue="T", offvalue="F")
c.grid(row=30, column=0, sticky=W)
c.place(x=300, y=125)
var4 = StringVar()
var4.set("F")
c = tk.Checkbutton(TOP6, text=".bmp", variable=var4, onvalue="T", offvalue="F")
c.grid(row=30, column=0, sticky=W)
c.place(x=400, y=125)
# Material name
label2 = StringVar()
input_name = Label(TOP6, text=' Material name ', font=(' Regular script ', 20)).place(x=35, y=180)
entry20 = Entry(TOP6, bg='#ffffff', width=8, textvariable=label2, font=(' Regular script ', 20)).place(x=25, y=230)
# Finished product name
label3 = StringVar()
input_name = Label(TOP6, text=' Finished product name ', font=(' Regular script ', 20)).place(x=450, y=180)
entry20 = Entry(TOP6, bg='#ffffff', width=8, textvariable=label3, font=(' Regular script ', 20)).place(x=440, y=230)
# Button
BUTTON = Button(TOP6, text="(๑¯ิε ¯ิ๑)",width = 15, height = 2,
font=(" Regular script ", 15))
BUTTON.place(x=205, y=320)
Copy code
Implementation steps ( 3、 ... and ): Build a function to receive data
Just having an input box is not enough , The meaning of the input box is to receive the required data , So we need to build a function to receive data .
# Receive the value of wechat QR code link
def get_QR():
QR = label.get()
return QR
# Receive material name
def get_name():
name = label2.get()
return name
# Receiving finished product name
def get_end_name():
end_name = label3.get()
return end_name
#.jpg
def get_v1():
v1 = var1.get()
return v1
#.png
def get_v2():
v2 = var2.get()
return v2
#.gif
def get_v3():
v3 = var3.get()
return v3
#.bmp
def get_v4():
v4 = var4.get()
return v4
Copy code
Implementation steps ( Four ): Build function function
After receiving the data, we build the function , And pass command Command binding button .
The following code section , We put the received data into the function and call .
Because the material has different formats , The generated finished product should be consistent with the format of the material , So we can divide it into four cases by checking different items , Using simple conditional judgment statements .
There is still a flaw in the design of this function , No successful prompt was generated ! You can do it yourself and add !!!!
BUTTON = Button(TOP6, text="(๑¯ิε ¯ิ๑)",width = 15, height = 2,command = QR_Code,
font=(" Regular script ", 15))
BUTTON.place(x=205, y=320)
Copy code
# Image generation function part
def newmethod718():
return myqr
def QR_Code():
QR = get_QR()
name = get_name()
end_name = get_end_name()
v1 = get_v1()
v2 = get_v2()
v3 = get_v3()
v4 = get_v4()
if v1 == 'T' and v2 == 'F' and v3 == 'F' and v4 == 'F':
newmethod718().run(
words=QR,
# After scanning QR code , Display content , Or jump Links
version=5, # Set fault tolerance
level='H', # Control error correction level , The scope is L、M、Q、H, From left to right
picture=name+'.jpg', # The directory of the pictures , It could be moving pictures
colorized=True, # Black and white (False) Or color (True)
contrast=1.0, # To adjust the contrast of the picture ,1.0 Represents the original picture . The default is 1.0.
brightness=1.0, # Used to adjust the brightness of the picture , Same as above .
save_name=end_name+'.jpg',
)
elif v2 == 'T' and v1 == 'F' and v3 == 'F' and v4 == 'F':
newmethod718().run(
words=QR,
# After scanning QR code , Display content , Or jump Links
version=5, # Set fault tolerance
level='H', # Control error correction level , The scope is L、M、Q、H, From left to right
picture=name+'.png', # The directory of the pictures , It could be moving pictures
colorized=True, # Black and white (False) Or color (True)
contrast=1.0, # To adjust the contrast of the picture ,1.0 Represents the original picture . The default is 1.0.
brightness=1.0, # Used to adjust the brightness of the picture , Same as above .
save_name=end_name+'.png',
)
elif v3 == 'T' and v1 == 'F' and v2 == 'F' and v4 == 'F':
newmethod718().run(
words=QR,
# After scanning QR code , Display content , Or jump Links
version=5, # Set fault tolerance
level='H', # Control error correction level , The scope is L、M、Q、H, From left to right
picture=name+'.gif', # The directory of the pictures , It could be moving pictures
colorized=True, # Black and white (False) Or color (True)
contrast=1.0, # To adjust the contrast of the picture ,1.0 Represents the original picture . The default is 1.0.
brightness=1.0, # Used to adjust the brightness of the picture , Same as above .
save_name=end_name+'.gif',
)
elif v4 == 'T' and v1 == 'F' and v3 == 'F' and v2 == 'F':
newmethod718().run(
words=QR,
# After scanning QR code , Display content , Or jump Links
version=5, # Set fault tolerance
level='H', # Control error correction level , The scope is L、M、Q、H, From left to right
picture=name+'.bmp', # The directory of the pictures , It could be moving pictures
colorized=True, # Black and white (False) Or color (True)
contrast=1.0, # To adjust the contrast of the picture ,1.0 Represents the original picture . The default is 1.0.
brightness=1.0, # Used to adjust the brightness of the picture , Same as above .
save_name=end_name+'.bmp',
)
Copy code
Interface beautification
stay Python The graphical interface is not beautiful enough ? Three lines of code completely beautify your Tkinter Interface in , We've shown you how to beautify your... With three lines of code and one click tkinter Interface .
First quote ttkbootstrap library
from ttkbootstrap import Style
Copy code
And then TOP6=tk() Change to the following code .
style = Style()
style = Style(theme='minty')
TOP6 = style.master
Copy code
Complete code
from tkinter import *
import tkinter as tk
from ttkbootstrap import Style
from MyQR import myqr
style = Style()
style = Style(theme='minty')
TOP6 = style.master
#TOP6 = Tk()# Initialize a window
TOP6.geometry("575x375")
TOP6.iconbitmap(' Icon .ico')# Assign icons
TOP6.title(' Color dynamic QR code generator V1.0')# Assign icons
# Receive the value of wechat QR code link
def get_QR():
QR = label.get()
return QR
# Receive material name
def get_name():
name = label2.get()
return name
# Receiving finished product name
def get_end_name():
end_name = label3.get()
return end_name
#.jpg
def get_v1():
v1 = var1.get()
return v1
#.png
def get_v2():
v2 = var2.get()
return v2
#.gif
def get_v3():
v3 = var3.get()
return v3
#.bmp
def get_v4():
v4 = var4.get()
return v4
# Image generation function part
def newmethod718():
return myqr
def QR_Code():
QR = get_QR()
name = get_name()
end_name = get_end_name()
v1 = get_v1()
v2 = get_v2()
v3 = get_v3()
v4 = get_v4()
if v1 == 'T' and v2 == 'F' and v3 == 'F' and v4 == 'F':
newmethod718().run(
words=QR,
# After scanning QR code , Display content , Or jump Links
version=5, # Set fault tolerance
level='H', # Control error correction level , The scope is L、M、Q、H, From left to right
picture=name+'.jpg', # The directory of the pictures , It could be moving pictures
colorized=True, # Black and white (False) Or color (True)
contrast=1.0, # To adjust the contrast of the picture ,1.0 Represents the original picture . The default is 1.0.
brightness=1.0, # Used to adjust the brightness of the picture , Same as above .
save_name=end_name+'.jpg',
)
if v2 == 'T' and v1 == 'F' and v3 == 'F' and v4 == 'F':
newmethod718().run(
words=QR,
# After scanning QR code , Display content , Or jump Links
version=5, # Set fault tolerance
level='H', # Control error correction level , The scope is L、M、Q、H, From left to right
picture=name+'.png', # The directory of the pictures , It could be moving pictures
colorized=True, # Black and white (False) Or color (True)
contrast=1.0, # To adjust the contrast of the picture ,1.0 Represents the original picture . The default is 1.0.
brightness=1.0, # Used to adjust the brightness of the picture , Same as above .
save_name=end_name+'.png',
)
if v3 == 'T' and v1 == 'F' and v2 == 'F' and v4 == 'F':
newmethod718().run(
words=QR,
# After scanning QR code , Display content , Or jump Links
version=5, # Set fault tolerance
level='H', # Control error correction level , The scope is L、M、Q、H, From left to right
picture=name+'.gif', # The directory of the pictures , It could be moving pictures
colorized=True, # Black and white (False) Or color (True)
contrast=1.0, # To adjust the contrast of the picture ,1.0 Represents the original picture . The default is 1.0.
brightness=1.0, # Used to adjust the brightness of the picture , Same as above .
save_name=end_name+'.gif',
)
if v4 == 'T' and v1 == 'F' and v3 == 'F' and v2 == 'F':
newmethod718().run(
words=QR,
# After scanning QR code , Display content , Or jump Links
version=5, # Set fault tolerance
level='H', # Control error correction level , The scope is L、M、Q、H, From left to right
picture=name+'.bmp', # The directory of the pictures , It could be moving pictures
colorized=True, # Black and white (False) Or color (True)
contrast=1.0, # To adjust the contrast of the picture ,1.0 Represents the original picture . The default is 1.0.
brightness=1.0, # Used to adjust the brightness of the picture , Same as above .
save_name=end_name+'.bmp',
)
# QR code analysis link
label = StringVar()
input_name = Label(TOP6, text=' QR code analysis link ', font=(' Regular script ', 20)).place(x=175, y=20)
entry20 = Entry(TOP6, bg='#ffffff', width=30, textvariable=label, font=(' Regular script ', 20)).place(x=75, y=80)
# Material type options
var1 = StringVar()
var1.set("F")
c = tk.Checkbutton(TOP6, text=".jpg", variable=var1, onvalue="T", offvalue="F")
c.grid(row=30, column=0, sticky=W)
c.place(x=100, y=125)
var2 = StringVar()
var2.set("F")
c = tk.Checkbutton(TOP6, text=".png", variable=var2, onvalue="T", offvalue="F")
c.grid(row=30, column=0, sticky=W)
c.place(x=200, y=125)
var3 = StringVar()
var3.set("F")
c = tk.Checkbutton(TOP6, text=".gif", variable=var3, onvalue="T", offvalue="F")
c.grid(row=30, column=0, sticky=W)
c.place(x=300, y=125)
var4 = StringVar()
var4.set("F")
c = tk.Checkbutton(TOP6, text=".bmp", variable=var4, onvalue="T", offvalue="F")
c.grid(row=30, column=0, sticky=W)
c.place(x=400, y=125)
# Material name
label2 = StringVar()
input_name = Label(TOP6, text=' Material name ', font=(' Regular script ', 20)).place(x=35, y=180)
entry20 = Entry(TOP6, bg='#ffffff', width=8, textvariable=label2, font=(' Regular script ', 20)).place(x=25, y=230)
# Finished product name
label3 = StringVar()
input_name = Label(TOP6, text=' Finished product name ', font=(' Regular script ', 20)).place(x=450, y=180)
entry20 = Entry(TOP6, bg='#ffffff', width=8, textvariable=label3, font=(' Regular script ', 20)).place(x=440, y=230)
BUTTON = Button(TOP6, text="(๑¯ิε ¯ิ๑)",width = 15, height = 2,command = QR_Code,
font=(" Regular script ", 15))
BUTTON.place(x=205, y=320)
TOP6.mainloop()
Copy code
Packaging with virtual environments , Publish your EXE Program
Epilogue
After learning, children can share it with their girlfriends ......, You can also entertain yourself . This project is my first learning Python I learned when I was , It's been a long time , It was quite hot at that time . If you like a friend, please give me “ One key, three links ”+“ Focus on ”.
Progress together !
copyright notice
author[Lu Jacob],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/02/202202020053042325.html
The sidebar is recommended
- How IOS developers learn Python Programming 22 - Supplement 1
- Python can meet any API you need
- Python 3 process control statement
- The 20th of 120 Python crawlers, 1637. All the way business opportunity network joined in data collection
- Datetime of pandas time series preamble
- How to send payslips in Python
- [Python] closure and scope
- Application of Python Matplotlib color
- leetcode 1627. Graph Connectivity With Threshold (python)
- Python thread 08 uses queues to transform the transfer scenario
guess what you like
-
Python: simple single player strange game (text)
-
Daily python, chapter 27, Django template
-
TCP / UDP communication based on Python socket
-
Use of pandas timestamp index
-
leetcode 148. Sort List(python)
-
Confucius old book network data collection, take one anti three learning crawler, python crawler 120 cases, the 21st case
-
[HTB] cap (datagram analysis, setuid capability: Python)
-
How IOS developers learn Python Programming 23 - Supplement 2
-
How to automatically identify n + 1 queries in Django applications (2)?
-
Data analysis starts from scratch. Pandas reads HTML pages + data processing and analysis
Random recommended
- 1313. Unzip the coding list (Java / C / C + + / Python / go / trust)
- Python Office - Python edit word
- Collect it quickly so that you can use the 30 Python tips for taking off
- Strange Python strip
- Python crawler actual combat, pyecharts module, python realizes China Metro data visualization
- DOM breakpoint of Python crawler reverse
- Django admin custom field stores links in the database after uploading files to the cloud
- Who has powder? Just climb who! If he has too much powder, climb him! Python multi-threaded collection of 260000 + fan data
- Python Matplotlib drawing streamline diagram
- The game comprehensively "invades" life: Python releases the "cool run +" plan!
- Python crawler notes: use proxy to prevent local IP from being blocked
- Python batch PPT to picture, PDF to picture, word to picture script
- Advanced face detection: use Dlib, opencv and python to detect face markers
- "Python 3 web crawler development practice (Second Edition)" is finally here!!!!
- Python and Bloom filters
- Python - singleton pattern of software design pattern
- Lazy listening network, audio novel category data collection, multi-threaded fast mining cases, 23 of 120 Python crawlers
- Troubleshooting ideas and summary of Django connecting redis cluster
- Python interface automation test framework (tools) -- interface test tool requests
- Implementation of Morse cipher translator using Python program
- [Python] numpy notes
- 24 useful Python tips
- Pandas table beauty skills
- Python tiktok character video, CV2 module, Python implementation
- I used Python to climb my wechat friends. They are like this
- 20000 words take you into the python crawler requests library, the most complete in history!!
- Answer 2: why can you delete the table but not update the data with the same Python code
- [pandas learning notes 02] - advanced usage of data processing
- How to implement association rule algorithm? Python code and powerbi visualization are explained to you in detail (Part 2 - actual combat)
- Python adds list element append() method, extend() method and insert() method [details]
- python wsgi
- Introduction to Python gunicorn
- Python dictionary query key value pair methods and examples
- Opencv Python reads video, processes and saves it frame by frame
- Python learning process and bug
- Imitate the up master and realize a live broadcast room controlled by barrage with Python!
- Essence! Configuration skills of 12 pandas
- [Python automated operation and maintenance road] path inventory
- Daily automatic health punch in (Python + Tencent cloud server)
- [Python] variables, comments, basic data types