python+pyqt实现12306图片验证效果

yipeiwu_com6年前Python基础

本文实例为大家分享了python实现12306图片验证效果的具体代码,供大家参考,具体内容如下

思路:在鼠标点击位置加一个按钮,然后再按钮中的点击事件中写一个关闭事件.

#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坐标 
    self.m_end_point=0 #y坐标 
    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() 
  #删除标记 
  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.exec_()) 

效果图:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持【听图阁-专注于Python设计】。

相关文章

对Python 2.7 pandas 中的read_excel详解

导入pandas模块: import pandas as pd 使用import读入pandas模块,并且为了方便使用其缩写pd指代。 读入待处理的excel文件: df =...

Python IDE Pycharm中的快捷键列表用法

Python IDE Pycharm中的快捷键列表用法

常用快捷键 全部快捷键 1、编辑(Editing) 2、查找/替换(Search/Replace) 3、运行(Running) 4、调试(Debugging) 5、导航(N...

PyQt5每天必学之事件与信号

PyQt5每天必学之事件与信号

这一部分我们将探索 PyQt5 的事件和信号是如何在应用程序中实现的。 Events事件 所有的GUI应用程序都是事件驱动的。应用程序事件主要产生自用户,但它们也可通过其他方法来产生,例...

浅谈Python里面小数点精度的控制

要求较小的精度 round()内置方法 这个是使用最多的,刚看了round()的使用解释,也不是很容易懂。round()不是简单的四舍五入的处理方式。 For the built-in...

python将多个文本文件合并为一个文本的代码(便于搜索)

但是,当一本书学过之后,对一般的技术和函数都有了印象,突然想要查找某个函数的实例代码时,却感到很困难,因为一本书的源代码目录很长,往往有几十甚至上百个源代码文件,想要找到自己想要的函数实...