Make my login code better write directly the script: from PyQt5 import QtWidgets, QtGui, uic, QtCore
import sys
from pathlib import Path
import os
import requests
import subprocess
from appdata import AppDataPaths
import webbrowser
import logging as log

class Ui(QtWidgets.QDialog):
    def __init__(self):
        super(Ui, self).__init__()
        uic.loadUi('login.ui', self)
        self.button_login.clicked.connect(self.apiCheck)
        ### log all errors to file
        #log path is in appdata folder
        self.app_data = AppDataPaths("Pixel Led Animator")
        self.app_data.setup()

        version = '2.2.5'


        pixmap = QtGui.QPixmap('logo.png')
        self.setWindowTitle("Pixel Led Animator" + " " + str(version))

        self.graphicsView_logo.setPixmap(pixmap)
        self.setWindowIcon(QtGui.QIcon('icon.ico'))
        self.show()

        def checkUpdate():
            try:
                response = requests.get('http://pixel-led-animator.com/API/version.txt')
            except:
                print("Connection Error")
                self.button_login.setText("Update Server Error")
            if response.text > version:
                ## show message box to update
                ret = QtWidgets.QMessageBox.question(self, 'Update Available', "New version: " + response.text +
                                                     "- click yes to update.",
                                                     QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
                if ret == QtWidgets.QMessageBox.Yes:
                    webbrowser.open('http://pixel-led-animator.com/API/update.php')
                    self.close()
                else:
                    pass

            else:
                print("No Update Available current version: " + version)
        def open_home_page(self):
            webbrowser.open('http://pixel-led-animator.com')
        self.button_login_2.clicked.connect(open_home_page)




        ## create export folder in appdata
        script_dir = self.app_data.app_data_path
        rel_path = "export"

        export_path = os.path.join(script_dir, rel_path)
        if not os.path.exists(export_path):
            os.makedirs(export_path)

        ## create export/sequencer folder in appdata
        script_dir = self.app_data.app_data_path
        rel_path = "export/sequencer"

        export_path = os.path.join(script_dir, rel_path)
        if not os.path.exists(export_path):
            os.makedirs(export_path)

        ## create export/combiner folder in appdata
        script_dir = self.app_data.app_data_path
        rel_path = "export/combiner"

        export_path = os.path.join(script_dir, rel_path)
        if not os.path.exists(export_path):
            os.makedirs(export_path)


        my_file_email = Path(self.app_data.app_data_path + "/email_file.txt")
        my_file_key = Path(self.app_data.app_data_path + "/key_file.txt")

        self.kurwa = "false"




        if my_file_email.is_file() and my_file_key.is_file():
            saved_email = my_file_email.read_text()
            self.lineEdit_email.setText(saved_email)
            self.email = self.lineEdit_email.text()
            saved_key = my_file_key.read_text()
            self.lineEdit_key.setText(saved_key)
            self.key = self.lineEdit_key.text()
            self.button_login.setText("Login")
            self.kurwa = "true"
            checkUpdate()

    def apiCheck(self):
        current_machine_id = subprocess.check_output('wmic csproduct get uuid').decode().split('\n')[1].strip()
        pc_id = str(current_machine_id)

        if self.kurwa == "true":
            self.key = self.lineEdit_key.text()
            self.email = self.lineEdit_email.text()
            query = {'check': "true", 'key': self.key, 'email': self.email,
                     'id': pc_id}
        else:
            email2 = self.lineEdit_email.text()
            key2 = self.lineEdit_key.text()
            query = {'create': "true", 'key': key2, 'email': email2,
                     'id': pc_id}
        try:
            response = requests.get('http://pixel-led-animator.com/API/api.php', params=query)
        except:
            print("Connection Error")
            self.button_login.setText("Login Server Error")

        if response.json() == "Created":
            email2 = self.lineEdit_email.text()
            key2 = self.lineEdit_key.text()
            script_dir = self.app_data.app_data_path
            rel_path1 = "key_file.txt"
            key_file_path = os.path.join(script_dir, rel_path1)
            key_file = open(key_file_path, 'w')
            try:
                key_file.write(str(key2))
            except:
                print("Error")
                self.login_button.setText("Cannot Write File Error #21 / Contact Support")

            rel_path2 = "email_file.txt"
            email_file_path = os.path.join(script_dir, rel_path2)
            email_file = open(email_file_path, 'w')
            try:
                email_file.write(str(email2))
            except:
                print("Error")
                self.login_button.setText("Cannot Write File Error #22 / Contact Support")
            import main2 as m
            m
            self.hide()
        elif response.json() == "Login":
            self.button_login.setText("Login.. Please wait")
            import main2 as m
            m
            self.hide()
        else:
            print("Error")
            print("Error" + response.json())
            self.button_login.setText("Error / " + response.json())






if __name__ == "__main__":
    QtWidgets.QApplication.setStyle('Fusion')
    QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)  # enable highdpi scaling
    QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True)  # use highdpi ico
    app1 = QtWidgets.QApplication(sys.argv)

    window = Ui()
    # window.checklicensefileexist()
    if window.kurwa == "true":
        window.apiCheck()
    sys.exit(app1.exec_())