python+pyqt實(shí)現(xiàn)12306圖片驗(yàn)證效果
本文實(shí)例為大家分享了python實(shí)現(xiàn)12306圖片驗(yàn)證效果的具體代碼,供大家參考,具體內(nèi)容如下
思路:在鼠標(biāo)點(diǎn)擊位置加一個(gè)按鈕,然后再按鈕中的點(diǎn)擊事件中寫一個(gè)關(guān)閉事件.
#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坐標(biāo)
self.m_end_point=0 #y坐標(biāo)
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()
#刪除標(biāo)記
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_())
效果圖:

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Python 的第三方調(diào)試庫 ???pysnooper?? 使用示例
這篇文章主要介紹了Python 的第三方調(diào)試庫 ???pysnooper?? 使用示例的相關(guān)資料,需要的朋友可以參考下2023-02-02
Django實(shí)現(xiàn)簡單網(wǎng)頁彈出警告代碼
今天小編就為大家分享一篇Django實(shí)現(xiàn)簡單網(wǎng)頁彈出警告代碼,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2019-11-11
Python如何計(jì)算語句執(zhí)行時(shí)間
這篇文章主要介紹了Python如何計(jì)算語句執(zhí)行時(shí)間,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-11-11
從基礎(chǔ)到進(jìn)階帶你玩轉(zhuǎn)Python中的JSON
python獲取屏幕截圖區(qū)域坐標(biāo)簡單代碼和思路
Python數(shù)據(jù)可視化之分析熱門話題“丁克家庭都怎么樣了”

