Preface:

Today we will use PyQT5 + QRCode to make a simple two-dimensional code generation tool. Let’s get started happily

The development tools

Python version: 3.6.4

Related modules:

PyQt5 module;

Qrcode module;

And some of the modules that come with Python.

Environment set up

Install Python and add it to the environment variable, and the PIP will install the appropriate module.

Introduction of the principle

Software interface:

Implementation idea:

First define the necessary components:

# --Label self.content_label = Qlabel (' content :') self.size_label = Qlabel (' size :') self.version_label = Qlabel (' version :') Self.margin_label = Qlabel (' Margins :') self.rendering_label = Qlabel (' effect :') self.show_label = Qlabel () # to make the image resizing Self.show_label.setScaledContents (True) # Maximum size when displayed self.show_label.setMaximumSize(200,) Content_edit = Qlineedit () self.content_edit.setText('Python novice learning 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))) # -- margin_spinbox = QSpinBox()

Then layout:

Self. Grid. AddWidget (self.rendering_label, 0, 0, 1, 1) self. Grid. AddWidget (self.show_label, 0, 0) self. 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)

Using QRCode and PyQT5 library to generate and save the function of two-dimensional code.

Finally, connect the signal:

PS: To change other parameters except margin, click the “generate QR code” button to generate a new QR code.

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

That’s the end of this article. Thank you for watching. The Python Gadgets series is suspended for the next series of articles

To thank you readers, I’d like to share with you some of my recent collection of dry programming goodies and give something back to every reader in the hope of helping you out.

Dry goods mainly include:

① More than 2000 Python e-books (mainstream and classic books are available)

(2) The Python Standard Library (Chinese version)

③ project source code (40 or 50 interesting and classic hands-on project and source code)

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

⑤Python Learning Roadmap (Goodbye to Slow Learning)

⑥ Two days of Python crawler training camp live access

All done~ complete source code + dry goods see personal profile or private message to obtain the relevant files.