Preface:

Using PyQT5 to implement a simple GUI. Without further ado, let’s begin happily

The development tools

Python version: 3.6.4

Related modules:

Requests module;

PyQt5 module;

Pillow 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

The principle is quite simple. First of all, go to a website that can sign the generative art for you according to the input name:

http://www.jiqie.com/a/14.htm

The website above looks something like this:

Simply grab the package (that is, open the developer tool or right mouse button of F12 to review the elements, and then click Give Me Design to see which requests need to be constructed for the generative art signature, and simply analyze them), you can find the link in the following figure to return to the generated art signature image link address:

The following parameters should be taken with the request:

It is easy to analyze:

1 id: your name 2 zhenbi: fixed value 3 id1 and id2: art signature type related parameters 4 id3 and id4: art signature font color related parameters

So we can easily implement the generative art signature according to the input name:

"' to generate the signature" 'def the generate (self) : font2ids_dict = {' sign an art: (' 901', '15'), 'kind business sign: [' 904', '15'], 'a business to sign: [' 905 ', '14'], 'real handwritten: [' 343', '14'], 'cartoon fun round words: [' 397', '14'], 'angry words' : [' 380', '14']} color2ids_dict = {' Black ': ['#000000', '#FFFFFF'], 'Blue': ['#0000FF', '#FFFFFF'], 'Red': ['#FF0000', '#FFFFFF'], 'Green': ['#00FF00', '#FFFFFF'], 'Yellow': ['#FFFF00', '#FFFFFF'], 'Pink': ['#FFC0CB', '#FFFFFF'], 'DeepSkyBlue': ['#00BFFF', '#FFFFFF'], 'Cyan': ['#00FFFF', '#FFFFFF'], 'Orange': ['#FFA500', '#FFFFFF'], 'Seashell': ['#FFF5EE', '#FFFFFF'] } url = 'http://www.jiqie.com/a/re14.php' headers = { 'Referer': 'http://www.jiqie.com/a/14.htm', 'the user-agent' : 'Mozilla / 5.0 (Windows NT 10.0; Win64; X64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36', 'Host': 'www.jiqie.com', 'Origin': 'http://www.jiqie.com' } ids_0 = font2ids_dict[self.font_combobox.currentText()] ids_1 = color2ids_dict[self.color_combobox.currentText()] data = { 'id': self.name_edit.text(), 'zhenbi': '20191123', 'id1': ids_0[0], 'id2': ids_0[1], 'id3': ids_1[0], 'id5': ids_1[1] } res = requests.post(url, headers=headers, data=data) image_url = re.findall(r'src="(.*?)"', res.text)[0] self.show_image_ext = image_url.split('.')[-1].split('?')[0] res = requests.get(image_url) fp = open('tmp.%s' % self.show_image_ext, 'wb') fp.write(res.content) fp.close() self.show_image = Image.open('tmp.%s' % self.show_image_ext).convert('RGB') self.updateimage() os.remove('tmp.%s' % self.show_image_ext)

Then PyQT5 can be used to create a simple GUI interface that looks something like this:

The image in the GUI can be displayed using qLabel (). A simple example is as follows:

1 show_label = QLabel()
2 show_image = Image.open('resource/image/ori.jpg').convert('RGB')
3 fp = io.BytesIO()
4 show_image.save(fp, 'JPEG')
5 qtimage = QtGui.QImage()
7 qtimage.loadFromData(fp.getvalue(), 'JPEG')
8 qtimage_pixmap = QtGui.QPixmap.fromImage(qtimage)
9 show_label.setPixmap(qtimage_pixmap)

These are basically PyQT5 operations.

This is the end of the article, thank you for watching, follow me every day to share Python widgets series, the next article to share PyQT5 + QRCode to make QR code generation tools

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.