Python + pyqt achieves 12306 image verification results,

Source: Internet
Author: User

Python + pyqt achieves 12306 image verification results,

The example in this article shares the code for python to implement the 12306 image verification effect for your reference. The details are as follows:

Train of Thought: Add a button at the mouse click position, and then write a close event in the click event in the button.

# Coding: UTF-8 from PyQt4.QtGui import * from PyQt4.QtCore import * from push_button import * from PIL import Image class Yanzheng (QWidget): def _ init _ (self, parent = None ): super (Yanzheng, self ). _ init _ (parent) self. m_start_point = 0 # x coordinate self. m_end_point = 0 # y coordinate self. coordinate = [] self. codeimage = ". /img/code.png "self. connect (self, SIGNAL ("addlable"), self. addpic) self. main_layout = QFormLayout () self. setLayout (self. main_layout) self. resize (293,190) self. pixmap = QPixmap (". /img/cur.png ") def addpic (self): print self. m_start_point, self. m_end_point xpoint = self. m_start_point ypoint = self. m_end_point-28 codepng2 = PushButton (self) codepng2.loadPixmapreal ('. /img/cur.png ') codepng2.setGeometry (self. m_start_point, self. m_end_point, 30,30) codepng2.show () # self. emit (SIGNAL ("dellabel"), self. codepng2) self. coordinate. append ("% s, % s" % (xpoint, ypoint) self. connect (codepng2, SIGNAL ("clicked ()"), lambda: self. dellabel (codepng2, xpoint, ypoint) # self. update () # Delete the flag def dellabel (self, q, x, y): print x, y self. coordinate. remove ("% s, % s" % (x, y) q. close () def mousePressEvent (self, event): if (event. type () = QEvent. mouseButtonPress): self. m_start_point = event. pos (). x ()-12 self. m_end_point = event. pos (). y ()-12 self. emit (SIGNAL ("addlable") def paintEvent (self, event): p = QPainter (self) p. drawPixmap (0, 0, QPixmap (self. codeimage) if _ name __= = '_ main _': import sys app = QApplication (sys. argv) inputurl = Yanzheng () inputurl. show () sys.exit(app.exe c _())

:

The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.