import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout, QGridLayout, QLineEdit, QLabel, QHBoxLayout, QDialog
from PyQt5.QtGui import *
from PyQt5.QtCore import Qt
import os
class MyApp(QWidget):
def __init__(self):
super().__init__()
self.initUI()
v = open('./data/number.txt')
self.number = int(v.readline())
v.close()
self.num = self.number
var = open('./data/ID.txt')
self.ID = var.readlines()
for line in self.ID:
line = line.strip()
var.close()
var1 = open('./data/PW.txt')
self.PW = var1.readlines()
for line1 in self.PW:
line1 = line1.strip()
var1.close()
def initUI(self):
self.vbox2 = QVBoxLayout()
self.dialog = QDialog()
self.vbox = QVBoxLayout()
self.grid = QGridLayout()
self.hbox = QHBoxLayout()
grid = QGridLayout()
lblID = QLabel('아이디')
grid.addWidget(lblID, 0, 0)
lblPW = QLabel('비밀번호')
grid.addWidget(lblPW, 1, 0)
self.identity = QLineEdit()
grid.addWidget(self.identity, 0, 1)
self.password = QLineEdit()
grid.addWidget(self.password, 1, 1)
self.grid.addLayout(grid, 0, 0)
login = QPushButton('로그인', self)
login.setCheckable(False)
login.toggle()
self.hbox.addWidget(login)
join = QPushButton('회원가입', self)
join.setCheckable(False)
join.toggle()
join.clicked.connect(self.log)
join.setStyleSheet('font: 8pt')
join.setMaximumWidth(55)
self.hbox.addWidget(join)
self.grid.addLayout(self.hbox, 1, 0)
self.setLayout(self.grid)
self.setWindowTitle('로그인')
self.setGeometry(300, 300, 300, 200)
self.show()
def log(self):
if self.number == 0:
self.ID.append(self.identity.text())
self.PW.append(self.password.text())
self.number = self.number + 1
else:
for i in range(self.number):
if self.ID[i] == self.identity.text():
self.dlg()
break
elif i == self.number - 1:
self.ID.append(self.identity.text())
self.PW.append(self.password.text())
self.number += 1
break
self.identity.setText('')
self.password.setText('')
var1 = open("./data/ID.txt", 'w')
for i in range(self.number):
var1.write(self.ID[i]+'\n')
var1.write('\n')
var1.close()
var2 = open("./data/PW.txt", 'w')
for i in range(self.number):
var2.write(self.PW[i]+'\n')
var2.write('\n')
var2.close()
v = open('./data/number.txt', 'w')
v.write(str(self.number))
v.close()
v1 = open('./data/information.txt','w')
for i in range(self.number):
v1.write(self.ID[i]+' '+self.PW[i])
v1.write('\n')
v1.close()
def dlg(self):
self.label = QLabel('이미 사용된 아이디 입니다', self.dialog)
font1 = self.label.font()
font1.setPointSize(13)
self.label.setFont(font1)
self.label.move(40, 70)
closebtn = QPushButton('확인', self.dialog)
closebtn.move(180, 140)
closebtn.clicked.connect(self.Close)
self.dialog.setWindowTitle('로그인')
self.dialog.resize(270, 180)
self.dialog.show()
def Close(self):
self.dialog.close()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MyApp()
sys.exit(app.exec_())
#파일: ID.txt, PW.txt, number.txt: 0, information.txttop of page

실제 작동 상태를 확인하려면 라이브 사이트로 이동하세요.
2022.8.13.
2022.8.13.
댓글 0개
좋아요
댓글(0)
더 이상 게시물에 대한 댓글 기능이 지원되지 않습니다. 자세한 사항은 사이트 소유자에게 문의하세요.
bottom of page


