반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- venv 설치
- 파이썬 가상환경 설치방법
- 파이썬 네이버 로그인
- Selenium 셀렉터잡기
- 네이버부동산크롤링
- vscode venv 설치
- 왕초보 파이썬 실행
- 파이썬 환경설정
- pywinauto 윈도우제어
- 날짜 정규식
- 파이썬 가상환경 설치
- Python
- 네이버커머스API
- 커머스API
- pycdc.exe
- Uipath 설치방법
- pywinauto
- UiPath
- selenium
- Uipath 기초
- 네이버 로그인 영수증 해결
- 파이썬네이버부동산
- pywinauto 윈도우
- 네이버매물크롤링
- Element is not clickable at point
- 네이버 로그인 하기
- pycdas.exe
- 네이버 로그인 캡챠해결
- uipath 입문
- 가상환경설치
Archives
- Today
- Total
콘솔워크
[PyQt, PySide6] 프로그램 실행 시 로그인 기능 구현하기 본문
반응형
프로그램을 최초 실행했을 때, 로그인화면으로 접속해서 id와 pw를 입력받고, 맞으면 다음화면, 아니면 해당 화면에 남아있게 짜봤습니다.
id, pw 부분은 각자의 데이터베이스에 맞게 수정해주세요.
if 1 == 1:
import sys
import warnings
import os
sys.path.append(os.path.dirname(os.path.abspath(os.path.dirname(__file__))))
warnings.simplefilter("ignore", UserWarning)
sys.coinit_flags = 2
from tkinter import *
from PySide6.QtCore import *
from PySide6.QtGui import *
from PySide6.QtWidgets import *
from datetime import datetime
from common.chrome import *
from dtos.gui_dto import *
from config import *
from features.google_sheet import login_sheet
from config import get_save_data_ACCOUNT, write_save_data_ACCOUNT
from common.utils import global_log_append
def my_exception_hook(exctype, value, traceback):
print(exctype, value, traceback)
global_log_append(str(value))
sys._excepthook(exctype, value, traceback)
sys.excepthook = my_exception_hook
class MainUI():
# 초기화
def __init__(self):
self.login_widget = LoginWidget()
self.app_widget = AppWidget()
self.login_widget.login_checked.connect(self.app_widget.initUI)
self.login_widget.initLoginUI()
class LoginWidget(QWidget):
login_checked = Signal()
def __init__(self):
super().__init__()
saved_account = get_save_data_ACCOUNT()
self.saved_login_id = saved_account["id"]
self.saved_login_pw = saved_account["pw"]
def login_button_clicked(self):
user_id = self.login_id_edit.text()
user_pw = self.login_pw_edit.text()
if not user_id or not user_pw:
QMessageBox.warning(self, "로그인실패", "아이디, 비밀번호를 확인해주세요.")
return
if login_sheet(user_id, user_pw):
QMessageBox.information(self, "로그인성공", "로그인 하였습니다.")
self.login_checked.emit()
self.destroy()
else:
QMessageBox.warning(self, "로그인실패", "아이디, 비밀번호를 확인해주세요.")
return
# 저장 파일
def save_button_clicked(self):
login_id = self.login_id_edit.text()
login_pw = self.login_pw_edit.text()
question_msg = "저장하시겠습니까?"
reply = QMessageBox.question(
self, "계정 저장", question_msg, QMessageBox.Yes, QMessageBox.No
)
if reply != QMessageBox.Yes:
return
write_save_data_ACCOUNT({"id": login_id, "pw": login_pw})
QMessageBox.information(self, "저장성공", "저장 하였습니다.")
def initLoginUI(self):
# 계정
login_groupbox = QGroupBox("로그인")
self.login_id_edit = QLineEdit(f"{self.saved_login_id}")
self.login_id_edit.setPlaceholderText("아이디")
self.login_id_edit.setFixedWidth = 500
self.login_pw_edit = QLineEdit(f"{self.saved_login_pw}")
self.login_pw_edit.setEchoMode(QLineEdit.Password)
self.login_pw_edit.setPlaceholderText("비밀번호")
self.login_pw_edit.setFixedWidth = 500
self.login_button = QPushButton("로그인")
self.login_button.clicked.connect(self.login_button_clicked)
self.save_button = QPushButton("저장")
self.save_button.clicked.connect(self.save_button_clicked)
login_layout = QHBoxLayout()
login_layout.addWidget(self.login_id_edit, 2)
login_layout.addWidget(self.login_pw_edit, 2)
login_layout.addWidget(self.login_button, 1)
login_layout.addWidget(self.save_button, 1)
login_groupbox.setLayout(login_layout)
layout = QVBoxLayout()
layout.addWidget(login_groupbox)
self.setLayout(layout)
# 앱 기본 설정
self.setWindowTitle("Login")
self.resize(450, 150)
self.show()
class AppWidget(QWidget):
def __init__(self):
super().__init__()
# # 프로그램 닫기 클릭 시
def closeEvent(self, event):
quit_msg = "프로그램을 종료하시겠습니까?"
reply = QMessageBox.question(self, "프로그램 종료", quit_msg, QMessageBox.Yes, QMessageBox.No)
if reply == QMessageBox.Yes:
print(f"프로그램을 종료합니다.")
event.accept()
else:
print(f"종료 취소")
event.ignore()
# 메인 UI
def initUI(self):
vbox = QVBoxLayout()
self.setLayout(vbox)
# 앱 기본 설정
self.setWindowTitle("App")
self.resize(1200, 800)
self.show()
if __name__ == "__main__":
app = QApplication(sys.argv)
main_ui = MainUI()
sys.exit(app.exec_())
반응형
'프로그래밍 > python' 카테고리의 다른 글
pyqt pyside QPlainTextEdit 글자수세기 (0) | 2023.06.07 |
---|---|
파이썬 공백 제거한 문자열 반환하는 함수 (0) | 2023.06.06 |
python PySide6 QTableWidget 열 크기 맞추기 (0) | 2023.06.05 |
파이썬 openpyxl로 특정열의 특정셀의 셀서식(포맷)변경 (0) | 2023.06.02 |
파이썬 엑셀 파일 합치는 프로그램 (0) | 2023.06.02 |