- Katılım
- 9 Kas 2022
- Mesajlar
- 378
- Beğeniler
- 96
- İletişim
Arkadaşlar basit bir login loading python pyqt5 ile yapılmıştır forumda ihtiyacı olan arkadaşlar var ise kullanabilir ufak bir ayarlama ile password yerine istediğiniz key sistemini entegre edebilirsiniz.
Linkleri görebilmek için kayıt olmanız gerekmektedir
Linkleri görebilmek için kayıt olmanız gerekmektedir
Python:
# created by Fridibuck
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QLabel, QProgressBar, QLineEdit, QPushButton, QMessageBox
from PyQt5.QtCore import Qt, QTimer, QRectF, QPoint
from PyQt5.QtGui import QFont, QIcon, QPainterPath, QPainter, QBrush, QColor, QPixmap
class LoginWindow(QWidget):
def __init__(self):
super().__init__()
self.initUI()
self.oldPos = self.pos()
def initUI(self):
self.setWindowFlags(Qt.FramelessWindowHint)
self.setAttribute(Qt.WA_TranslucentBackground)
self.setStyleSheet("background-color: rgba(0, 0, 0, 0);")
layout = QVBoxLayout()
layout.setContentsMargins(40, 40, 40, 40)
layout.setSpacing(20)
self.label = QLabel("Fridibuck Login Page", self)
self.label.setStyleSheet("color: #ecf0f1; font-size: 24px; font-weight: bold;")
self.label.setAlignment(Qt.AlignCenter)
self.username = QLineEdit(self)
self.username.setPlaceholderText("Username")
self.username.setFont(QFont("Arial", 16))
self.username.setStyleSheet("""
QLineEdit {
border: 1px solid #bbb;
border-radius: 5px;
padding: 10px;
font-size: 16px;
background-color: white;
}
QLineEdit:focus {
border: 2px solid #3498db;
background-color: #e0e0e0;
}
""")
self.username.returnPressed.connect(self.handleLogin)
self.password = QLineEdit(self)
self.password.setPlaceholderText("Password")
self.password.setEchoMode(QLineEdit.Password)
self.password.setFont(QFont("Arial", 16))
self.password.setStyleSheet("""
QLineEdit {
border: 1px solid #bbb;
border-radius: 5px;
padding: 10px;
font-size: 16px;
background-color: white;
}
QLineEdit:focus {
border: 2px solid #3498db;
background-color: #e0e0e0;
}
""")
self.password.returnPressed.connect(self.handleLogin)
self.loginButton = QPushButton("Login", self)
self.loginButton.setFont(QFont("Arial", 16))
self.loginButton.setStyleSheet("""
QPushButton {
background-color: #3498db;
color: white;
border: none;
border-radius: 5px;
padding: 10px;
font-size: 16px;
}
QPushButton:hover {
background-color: #2980b9;
}
QPushButton:pressed {
background-color: #2471a3;
}
""")
self.loginButton.clicked.connect(self.handleLogin)
layout.addWidget(self.label)
layout.addWidget(self.username)
layout.addWidget(self.password)
layout.addWidget(self.loginButton)
self.setLayout(layout)
self.logo = QLabel(self)
self.logo.setPixmap(QPixmap("exit.png").scaled(40, 40, Qt.KeepAspectRatio, Qt.SmoothTransformation))
self.logo.setGeometry(self.width() - 40, 0, 40, 40)
self.logo.mousePressEvent = self.closeApplication
screen = QApplication.primaryScreen().geometry()
size = self.sizeHint()
self.setGeometry(
(screen.width() - size.width()) // 2,
(screen.height() - size.height()) // 2,
size.width(), size.height()
)
def resizeEvent(self, event):
super().resizeEvent(event)
self.logo.setGeometry(self.width() - 40, 0, 40, 40)
def paintEvent(self, event):
path = QPainterPath()
path.setFillRule(Qt.WindingFill)
path.addRoundedRect(QRectF(self.rect()), 20, 20)
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing, True)
painter.fillPath(path, QBrush(QColor(44, 62, 80, 255)))
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self.oldPos = event.globalPos()
def mouseMoveEvent(self, event):
if event.buttons() == Qt.LeftButton:
delta = QPoint(event.globalPos() - self.oldPos)
self.move(self.x() + delta.x(), self.y() + delta.y())
self.oldPos = event.globalPos()
def handleLogin(self):
if self.username.text() == 'admin' and self.password.text() == 'admin':
self.close()
self.loaderScreen = LoaderScreen()
self.loaderScreen.show()
else:
error_msg = QMessageBox(self)
error_msg.setWindowTitle('Error')
error_msg.setText('Invalid username or password')
error_msg.setStyleSheet("""
QMessageBox {
background-color: white;
color: black;
}
QMessageBox QLabel {
color: black;
}
QMessageBox QPushButton {
background-color: #3498db;
color: white;
border-radius: 5px;
padding: 5px 10px;
}
QMessageBox QPushButton:hover {
background-color: #2980b9;
}
""")
error_msg.exec_()
def closeApplication(self, event):
self.close()
class LoaderScreen(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint)
self.setAttribute(Qt.WA_TranslucentBackground)
layout = QVBoxLayout()
layout.setContentsMargins(50, 50, 50, 50)
layout.setSpacing(10)
self.label = QLabel("Loading...", self)
self.label.setStyleSheet("color: white; font-size: 30px;")
self.label.setAlignment(Qt.AlignCenter)
self.progress = QProgressBar(self)
self.progress.setRange(0, 100)
self.progress.setValue(0)
self.progress.setTextVisible(False)
self.progress.setStyleSheet("""
QProgressBar {
border: 2px solid grey;
border-radius: 10px;
background-color: #E0E0E0;
}
QProgressBar::chunk {
background-color: #3498db;
width: 20px;
margin: 1px;
}
""")
layout.addWidget(self.label)
layout.addWidget(self.progress)
self.setLayout(layout)
screen = QApplication.primaryScreen().geometry()
size = self.sizeHint()
self.setGeometry(
(screen.width() - size.width()) // 2,
(screen.height() - size.height()) // 2,
size.width(), size.height()
)
self.timer = QTimer(self)
self.timer.timeout.connect(self.updateProgress)
self.timer.start(50)
self.show()
def updateProgress(self):
value = self.progress.value()
if value < 100:
self.progress.setValue(value + 1)
else:
self.timer.stop()
self.close()
self.mainWindow = MainWindow()
self.mainWindow.show()
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setWindowTitle('Main Application')
self.setGeometry(100, 100, 800, 600)
self.setWindowIcon(QIcon('main_icon.png'))
layout = QVBoxLayout()
label = QLabel("Fridibuck", self)
label.setAlignment(Qt.AlignCenter)
label.setFont(QFont("Arial", 24))
label.setStyleSheet("color: #2c3e50;")
layout.addWidget(label)
self.setLayout(layout)
if __name__ == '__main__':
app = QApplication(sys.argv)
loginWindow = LoginWindow()
loginWindow.show()
sys.exit(app.exec_())