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

python+pyqt实现12306图片验证效果
本文实例为大家分享了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_())
效果图:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序猿小乙

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值