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

yipeiwu_com5年前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将json数据转换为csv格式的方法

假设.json文件中存储的数据为: {"type": "Point", "link": "http://www.dianping.com/newhotel/22416995", "c...

浅谈Python接口对json串的处理方法

最近学习Python接口测试,对于接口测试完全小白。大概一周的学习成果进行总结。 1.接口测试: 目前涉及到的只是对简单单一的接口进行参数传递,得到返回自。 2.关于各种概念: 2.1...

详解python中executemany和序列的使用方法

详解python中executemany和序列的使用方法 一 代码 import sqlite3 persons=[ ("Jim","Green"), ("Hu","...

Win10+GPU版Pytorch1.1安装的安装步骤

Win10+GPU版Pytorch1.1安装的安装步骤

安装cuda 更新nvidia驱动 打开GeForce Game Ready Driver或在GeForce Experience中下载符合自己gpu的程序。 选择cuda 打开nvi...

python 文本单词提取和词频统计的实例

这些对文本的操作经常用到, 那我就总结一下。 陆续补充。。。 操作: strip_html(cls, text) 去除html标签 separate_words(cls, text, m...