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

yipeiwu_com7年前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设计】。

相关文章

python3学习之Splash的安装与实例教程

python3学习之Splash的安装与实例教程

前言 Splash是一个javascript渲染服务。它是一个带有HTTP API的轻量级Web浏览器,使用Twisted和QT5在Python 3中实现。QT反应器用于使服务完全异步,...

python pandas 对series和dataframe的重置索引reindex方法

reindex更多的不是修改pandas对象的索引,而只是修改索引的顺序,如果修改的索引不存在就会使用默认的None代替此行。且不会修改原数组,要修改需要使用赋值语句。 series.r...

简单了解python代码优化小技巧

简单了解python代码优化小技巧

对比以下两种写法,思考一下为何可以这样写。 成绩在 [0,50)、[50,60)、[60,80)、[80,100)、100、其它 score = float(input("请输入你的...

Python中List.count()方法的使用教程

 count()方法返回obj出现在列表的次数。 语法 以下是count()方法的语法: list.count(obj) 参数   &nbs...

Python使用email模块对邮件进行编码和解码的实例教程

解码邮件 python自带的email模块是个很有意思的东西,它可以对邮件编码解码,用来处理邮件非常好用。 处理邮件是一个很细致的工作,尤其是解码邮件,因为它的格式变化太多了,下面先看看...