PyQT5从其他文件打开新窗口

时间:2020-01-18 14:52:38

标签: python pyqt5

我在这里看到了几个不同的stackoverflow问题,似乎无法解决此问题。

我有2个文件,其中1个是login.py,另一个是spotify.py,登录后,我想显示其他形式,但是我认为我的课程有问题。

首次登录:

from scipy import stats
#Data of group 1
a = np.array([42.1, 80.0, 30.0, 45.8, 57.7, 80.0, 82.4, 66.2, 66.9, 79.0])
#Data of group 2
b = np.array([80.7, 85.1, 88.6, 81.7, 69.8, 79.5, 107.2, 69.3, 80.9, 63.0])
t2, p2 = stats.ttest_ind(a,b)

另一个文件与此类似,但是我似乎无法执行另一个窗口,我正在使用这个丑陋的选项,打算更改它:

# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'spotify.ui'
#
# Created by: PyQt5 UI code generator 5.13.0
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
from app import SpotifyApp
import pathlib
import requests
import json
import sys
from monik import monikAssistant

class LoginForm(object):
    monik = monikAssistant()
    def setupUi(self, Form):
        Form.setObjectName("Login")
        Form.resize(482, 390)
        Form.setMaximumWidth(Form.width())
        Form.setMaximumHeight(Form.height())
        Form.setStyleSheet("background:#1DB954;")
        self.lineEdit = QtWidgets.QLineEdit(Form)
        self.lineEdit.setGeometry(QtCore.QRect(10, 170, 431, 51))
        self.lineEdit.setStyleSheet("background:white;\n"
"border-radius:5px;\n"
"color:gray;\n"
"font-weight:bold;")
        self.lineEdit.setObjectName("lineEdit")
        self.label_2 = QtWidgets.QLabel(Form)
        self.label_2.setGeometry(QtCore.QRect(10, 130, 211, 21))
        self.label_2.setStyleSheet("color:white;\n"
"font-weight:bold;\n"
"font-size:15px;")
        self.label_2.setObjectName("label_2")
        self.submitBtn = QtWidgets.QPushButton(Form)
        self.submitBtn.setGeometry(QtCore.QRect(10, 310, 431, 51))
        self.submitBtn.setStyleSheet("QPushButton { font-weight:bold; border:2px solid white; color:white; border-radius:5px; }"
"QPushButton:hover:!pressed { background:blue; border:2px solid blue; }"
)
        self.submitBtn.setObjectName("pushButton")
        self.submitBtn.setCursor(QtCore.Qt.PointingHandCursor)
        self.lineEdit_2 = QtWidgets.QLineEdit(Form)
        self.lineEdit_2.setEchoMode(QtWidgets.QLineEdit.Password)
        self.lineEdit_2.setGeometry(QtCore.QRect(10, 240, 431, 51))
        self.lineEdit_2.setStyleSheet("background:white;\n"
"border-radius:5px;\n"
"color:gray;\n"
"font-weight:bold;")
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.label = QtWidgets.QLabel(Form)
        self.label.setGeometry(QtCore.QRect(80, -20, 341, 131))
        self.label.setObjectName("label")

        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Spotify Testing"))
        self.label.setText(_translate("Form", "<html><head/><body><p><img src=\":/imagem/logo.png\"/></p></body></html>"))
        self.lineEdit.setPlaceholderText(_translate("Form", "     Username"))
        self.label_2.setText(_translate("Form", "Log into your account"))
        self.lineEdit_2.setPlaceholderText(_translate("Form", "     Password"))
        self.submitBtn.setText(_translate("Form", "LOGIN"))
        self.submitBtn.clicked.connect(self.attempLogin)

    def attempLogin(self):
        email = self.lineEdit.text()
        password = self.lineEdit_2.text()
        self.loginRequest(email,password)

    def loginRequest(self,user,password):    
        url = 'https://myprivateurl.com/api.php'

        params = dict(
            email=user,
            password=password
        )

        resp = requests.get(url=url, params=params)
        #data = resp.json()
        import spotify
        data = resp.text
        if data == "true":
            self.monik.speakText("You logged in successfully.")    
            import os
            Form.close()
            os.system('python3 spotify.py {} {}'.format(user,password)) 
        else:
            self.monik.speakText("Your login is not working or your plan is expired.")    

import imagem_rc



if __name__ == "__main__":
    app = QtWidgets.QApplication(sys.argv)
    Form = QtWidgets.QWidget()
    ui = LoginForm()
    ui.setupUi(Form)
    Form.show()
    sys.exit(app.exec_())

您能建议我该怎么做吗?

0 个答案:

没有答案
相关问题