/
Horys
/
Python
Обзор
Документация
Войти
/
Horys
/
Python
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
password_GUI.py
61 строка
2 KB
Виктор
Create: password_GUI.py
19 июл 2026, 18:45
Верифицирован
19 июл 2026, 18:45
a7b2f00
Код
Авторство
О чём код?
import sys from PyQt5.QtWidgets import (QApplication, QMainWindow, QLineEdit, QPushButton, QCheckBox, QVBoxLayout, QWidget) import secrets import string class MainWindow(QMainWindow): def __init__(self): super().__init__() self.setGeometry(700, 300, 300, 100) self.initUI() def initUI(self): self.setWindowTitle("Генератор паролей.") self.password_output = QLineEdit(self) self.password_output.setReadOnly(True) self.password_output.setPlaceholderText("Пароль появится здесь.") self.line_edit = QLineEdit(self) self.line_edit.setPlaceholderText("Введите длину пароля.") self.checkBox = QCheckBox(self) self.checkBox.setText("Использовать спецсимволы?") self.copy_button = QPushButton("Скопировать", self) self.button = QPushButton("Сгенерировать", self) self.button.clicked.connect(self.on_generate) layout = QVBoxLayout() layout.addWidget(self.line_edit) layout.addWidget(self.checkBox) layout.addWidget(self.button) layout.addWidget(self.password_output) layout.addWidget(self.copy_button) container = QWidget() container.setLayout(layout) self.setCentralWidget(container) self.copy_button.clicked.connect(self.on_copy) def on_copy(self): QApplication.clipboard().setText(self.password_output.text()) def on_generate(self): length = int(self.line_edit.text()) # взять длину из поля use_special = self.checkBox.isChecked() # проверить галочку password = self.generate_password(length, use_special) # сгенерировать self.password_output.setText(password) # показать результат def generate_password(self, length, use_special=True): # добавляем строки и спецсимволы. alphabet = string.ascii_letters + string.digits # Спрашиваем, нужны спецсимволы или нет. if use_special: return ''.join(secrets.choice(alphabet + string.punctuation) for i in range(length)) else: return ''.join(secrets.choice(alphabet) for i in range(length)) if __name__ == "__main__": app = QApplication(sys.argv) window = MainWindow() window.show() sys.exit(app.exec_())