Preface:

Today we use PyQt5+ Qrcode to make a simple TWO-DIMENSIONAL code generation tool. Let’s have a good time

The development tools

**Python version: **3.6.4

Related modules:

PyQt5 module;

Qrcode module;

And some modules that come with Python.

Environment set up

Install Python and add it to the environment variables. PIP installs the required related modules.

Introduction of the principle

Software Interface:

Implementation idea:

Define the necessary components first:

# Define component
		# --Label
		self.content_label = QLabel('content:)
		self.size_label = QLabel('size:)
		self.version_label = QLabel('version:)
		self.margin_label = QLabel('margin:)
		self.rendering_label = QLabel(':')
		self.show_label = QLabel()
		# Make the image scalable
		self.show_label.setScaledContents(True)
		# Maximum size for display
		self.show_label.setMaximumSize(200.200)
		# -- Input field
		self.content_edit = QLineEdit()
		self.content_edit.setText('Python Novice Exchange Group: 594356095')
		Button # -
		self.generate_button = QPushButton('Generate qr code')
		self.save_button = QPushButton('Save qr code')
		# -- dropdown box
		self.version_combobox = QComboBox()
		for i in range(1.41):
			self.version_combobox.addItem('%s' % str(i))
		self.size_combobox = QComboBox()
		for i in range(8.40.2):
			self.size_combobox.addItem('%s * %s' % (str(i*29), str(i*29)))
		# -- Trimmer box
		self.margin_spinbox = QSpinBox()
Copy the code

Then the layout:

Self.grid. addWidget(self.rendering_label, 0, 0, 1, 1) self.grid.addWidget(self.show_label, 0, 1) 0, 5, 5) self.grid.addWidget(self.content_label, 0, 5, 1, 1) self.grid.addWidget(self.content_edit, 0, 6, 1, 3) self.grid.addWidget(self.version_label, 1, 5, 1, 1) self.grid.addWidget(self.version_combobox, 1, 6, 1, 1) self.grid.addWidget(self.size_label, 2, 5, 1, 1) self.grid.addWidget(self.size_combobox, 2, 6, 1, 1) self.grid.addWidget(self.margin_label, 3, 5, 1, 1) self.grid.addWidget(self.margin_spinbox, 3, 6, 1, 1) self.grid.addWidget(self.generate_button, 4, 5, 1, 2) self.grid.addWidget(self.save_button, 5, 5, 1, 2)Copy the code

Use Qrcode and PyQT5 library to generate and save two-dimensional code function.

Finally, the signal was passed on:

PS: Except the margin, to change other parameters, you need to click the button to generate two-dimensional code to generate a new two-dimensional code.

        self.generate_button.clicked.connect(self.genQrcode)
		self.save_button.clicked.connect(self.saveQrcode)
		self.margin_spinbox.valueChanged.connect(self.genQrcode)
Copy the code

That’s the end of this article, thanks for watching, and the next installment of the Python gadget series will be a mini-game series

To thank you readers, I’d like to share some of my recent programming favorites to give back to each and every one of you in the hope that they can help you.

Dry goods mainly include:

① Over 2000 Python ebooks (both mainstream and classic books should be available)

②Python Standard Library (Most Complete Chinese version)

③ project source code (forty or fifty interesting and classic practice projects and source code)

④Python basic introduction, crawler, Web development, big data analysis video (suitable for small white learning)

⑤ A Roadmap for Learning Python

⑥ Two days of Python crawler boot camp live access

All done~ complete source code + dry goods see personal profile or private letter to obtain relevant documents.