多窗口传递信号,无边框移动,12306验证码,pyqt5

发布时间:2020-07-16 13:46:33 作者:libinqi456
来源:网络 阅读:988

多窗口传递信号,无边框移动,12306验证码,pyqt5
Form1:

from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from Form1 import Ui_Form
import sys,qdarkstyle
import Form2_Main

class Form1_Main( QDialog,Ui_Form):
    def __init__(self):
        super(Form1_Main,self).__init__()
        self.setupUi(self)
        #self.setAttribute(Qt.WA_TranslucentBackground)
        # 设置窗体无边框
        self.setWindowFlags(Qt.FramelessWindowHint)
        self.pushButton.clicked.connect(self.showFrom2)
        self.pushButton_2.clicked.connect(self.close)

    def showFrom2(self):
        F2_window = Form2_Main.Form2_Main()
        F2_window.Form2_signal.connect(self.showFrom2msg)
        F2_window.show()
        F2_window.exec_()

    def showFrom2msg(self,strs):
        print(strs)

    def mousePressEvent(self, QMouseEvent):
        if QMouseEvent.button() == Qt.LeftButton:
            self.flag = True
            # 获取鼠标相对窗口的位置
            self.m_Position = QMouseEvent.globalPos() - self.pos()
            QMouseEvent.accept()
            # 更改鼠标图标
            self.setCursor(QCursor(Qt.OpenHandCursor))

    def mouseMoveEvent(self, QMouseEvent):
        if Qt.LeftButton and self.flag:
            # 更改窗口位置
            self.move(QMouseEvent.globalPos()-self.m_Position)
            QMouseEvent.accept()

    def mouseReleaseEvent(self, QMouseEvent):
        self.flag = False
        self.setCursor(QCursor(Qt.ArrowCursor))

if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = Form1_Main()
    app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
    window.show()
    sys.exit(app.exec_())

多窗口传递信号,无边框移动,12306验证码,pyqt5
Form2:

from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from Form2 import Ui_Form
import sys,requests,base64,qdarkstyle

class Form2_Main(QDialog,Ui_Form):
    Form2_signal = pyqtSignal(str)
    def __init__(self,parent=None):
        super(Form2_Main,self).__init__(parent)
        self.setupUi(self)
        self.setWindowFlags(Qt.FramelessWindowHint)
        self.setWindowModality(Qt.ApplicationModal)
        self.setModal(True)
        self.pushButton.clicked.connect(self.get_pic)
        self.pushButton_2.clicked.connect(self.close)

    def backStr(self):
        self.Form2_signal.emit('Form2 message')#验证成功返回数据

    def get_pic(self):
        url = 'https://kyfw.12306.cn/passport/captcha/captcha-image64?login_site=E&module=login&rand=sjrand'

        try:
            r = requests.get(url)
            print('content: ',r.content)
            dic = r.json()
            print('json:',dic)
            png = base64.b64decode(dic['image'])
            print('png: ',png)
            photo = QPixmap(100,100)
            photo.loadFromData(png)
            self.label.setPixmap(photo)
            self.Form2_signal.emit('Form2 message')  # 验证成功返回数据

        except Exception as e:
            print('Exception',e)

    def mousePressEvent(self, event):

        if(event.button()==Qt.LeftButton):
            self.flag = True
            self.m_Position = event.globalPos() - self.pos()
            event.accept()
            self.setCursor(QCursor(Qt.OpenHandCursor))

    def mouseMoveEvent(self, event):
        if Qt.LeftButton and self.flag:
            self.move(event.globalPos() - self.m_Position)
            event.accept()

    def mouseReleaseEvent(self, event):
        self.flag = False
        self.setCursor(QCursor(Qt.ArrowCursor))

if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = Form2_Main()
    app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
    window.show()
    sys.exit(app.exec_())

运行效果:
多窗口传递信号,无边框移动,12306验证码,pyqt5

推荐阅读:
  1. PyQt5快速入门(二)PyQt5信号槽机制
  2. 关于WPF多窗口消息传递的简单实现

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

pyqt5 加载 12306

上一篇:如何使用MySQL授权命令grant

下一篇:如何在php中删除数组的键名

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》