I just finished my first GUI app, a Password Generator that can take any characters you want(I've added some default characters to make your life easier), and a password length up to 999, and some small features like copy to clipboard and clear button...
I used PyQt5
to build my GUI and some helpful modules like pyperclip
, webbrowser
...
This is what the app looks like on Windows:
I used Pyinstaller to convert .py to .exe download the Password Generator.exe here
Here's the source code:
#!/usr/bin/env python3.5.2
from PyQt5.QtWidgets import*
from PyQt5.QtCore import*
from PyQt5.QtGui import*
import random
import pyperclip
import webbrowser
import sys
class Password_Generator(QWidget):
def __init__(self):
QWidget.__init__(self)
layout = QGridLayout()
self.menuBar = QMenuBar()
self.default_characters = QPushButton()
self.characters = QLineEdit()
self.passwordlength = QLineEdit()
self.pl_option = QComboBox()
self.progress = QProgressBar()
self.generate = QPushButton("Generate Password")
self.result = QLineEdit()
self.clipboard = QPushButton("Copy to clipboard")
self.clear = QPushButton("Clear")
self.fileMenu = QMenu("File", self)
self.clearAction = self.fileMenu.addAction("Clear")
self.exitAction = self.fileMenu.addAction("Exit")
self.menuBar.addMenu(self.fileMenu)
self.helpMenu = QMenu("Help", self)
self.source_code = self.helpMenu.addAction("Source Code")
self.information = self.helpMenu.addAction("About Me")
self.menuBar.addMenu(self.helpMenu)
self.characters.setPlaceholderText("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890$@^`,|%;.~()/\{}:?[]=-+_#!")
self.characters.setFixedWidth(524)
self.passwordlength.setPlaceholderText("password length")
self.passwordlength.setFixedWidth(85)
self.passwordlength.setAlignment(Qt.AlignHCenter)
self.passwordlength.setValidator(QIntValidator(0, 999))
self.passwordlength.setMaxLength(3)
self.pl_option.setFixedWidth(58)
self.pl_option.addItems(["Default", "8", "16", "32", "64", "128"])
self.progress.setValue(0)
self.progress.setAlignment(Qt.AlignHCenter)
self.generate.setFixedWidth(125)
self.default_characters.setFixedWidth(24)
self.default_characters.setIcon(QIcon(r'C:\Users\SalahGfx\Desktop\Password Generator Files\file-default-icon-62367.png'))
self.result.setReadOnly(True)
self.result.setFixedWidth(425)
layout.addWidget(self.default_characters, 0, 0)
layout.addWidget(self.characters, 0, 1, 1, 2)
layout.addWidget(self.passwordlength, 0, 3)
layout.addWidget(self.pl_option, 0, 4)
layout.addWidget(self.generate, 1, 0, 1, 2)
layout.addWidget(self.result, 1, 2)
layout.addWidget(self.progress, 1, 3, 1, 2)
layout.addWidget(self.clipboard, 3, 0, 1, 3)
layout.addWidget(self.clear, 3, 3, 1, 2)
layout.setMenuBar(self.menuBar)
self.setLayout(layout)
self.setFocus()
self.setWindowTitle("Password Generator")
self.generate.clicked.connect(self.generated)
self.clipboard.clicked.connect(self.clipboard_copy)
self.clear.clicked.connect(self.cleared)
self.default_characters.clicked.connect(self.default)
self.pl_option.currentIndexChanged.connect(self.numbers)
self.clearAction.triggered.connect(self.cleared)
self.exitAction.triggered.connect(self.exit)
self.source_code.triggered.connect(self.get_source_code)
self.information.triggered.connect(self.info_window)
self.new_window = Info_Window()
self.new_window.setWindowIcon(QIcon(r'C:\Users\SalahGfx\Desktop\Password Generator Files\Lock_closed_key_2-512.png'))
self.new_window.setWindowTitle("About Me")
def get_source_code(self):
webbrowser.open(r"C:\Users\SalahGfx\Desktop\Password Generator Files\Source Code.txt")
def info_window(self):
self.new_window.setWindowFlags(Qt.WindowCloseButtonHint)
self.new_window.show()
self.new_window.setFixedSize(665, 350)
def exit(self):
sys.exit(app.exec_())
def numbers(self):
if self.pl_option.currentText() == 'Default':
self.passwordlength.setText(None)
else:
self.passwordlength.setText(self.pl_option.currentText())
def default(self):
characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890$@^`,|%;.~()/\{}:?[]=-+_#!"
self.characters.setText(characters)
def generated(self):
try:
characters = self.characters.text()
password_length = int(self.passwordlength.text())
except Exception:
return
self.password = ""
for i in range(password_length):
try:
characters_index = random.randrange(len(characters))
except Exception:
return
self.password = self.password + characters[characters_index]
self.progress.setValue(100)
self.result.setText(self.password)
def clipboard_copy(self):
if len(self.result.text()) > 0:
pyperclip.copy(self.result.text())
QMessageBox.information(self, "Information", "Password has been copied to clipboard!")
else:
return
def cleared(self):
self.characters.setText("")
self.passwordlength.setText("")
self.progress.setValue(0)
self.result.setText("")
self.passwordlength.setText(None)
self.pl_option.setCurrentIndex(0)
class Info_Window(QDialog):
def __init__(self):
QDialog.__init__(self)
info_layout = QGridLayout()
self.info = QLabel("Password Generator\n"
"Version 1.0\n"
"Contact Riverbank at [email protected]\n"
"Copyright © free 2016 Riverbank Computing Limited under GNU General Public License version 3\n"
"Contact Me at [email protected]\n"
"Copyright © free 2017 Salah Gfx Open Source Project\n")
self.about_me = QLabel("My name is Salah, I'm a college student, I study computer science and mathematics, I'm also a graphic designer\n"
"and python programmer, I'm a self taught, I have 3 years of experience in 3D design and 1 year in coding, I wish\n"
" to make 3D games in the future, combining those knowledges I believe I can make it, this app is my first GUI app,\n"
" I used to run all my codes and scripts in the console but now it feels different how you can share your work with\n"
" normal people, it is just amazing and helpful, have a nice day and I wish for you a successful life.")
self.Font = QFont()
self.Font.setBold(True)
self.about_me.setFont(self.Font)
self.Hline = QFrame()
self.Hline.setFrameShape(self.Hline.HLine)
self.Hline.setFrameShadow(self.Hline.Sunken)
self.Vline = QFrame()
self.Vline.setFrameShape(self.Vline.VLine)
self.Vline.setFrameShadow(self.Vline.Sunken)
self.image_label = QLabel()
pixmap = QPixmap(r"C:\Users\SalahGfx\Desktop\Password Generator Files\SLH-GFX2.png")
self.image_label.setPixmap(pixmap)
info_layout.addWidget(self.info, 0, 2)
info_layout.addWidget(self.Vline, 0, 1)
info_layout.addWidget(self.image_label, 0, 0)
info_layout.addWidget(self.Hline, 1, 0, 1, 3)
info_layout.addWidget(self.about_me, 2, 0, 1, 3)
self.setLayout(info_layout)
app = QApplication(sys.argv)
window = Password_Generator()
window.setFixedSize(732, 120)
window.setWindowIcon(QIcon(r'C:\Users\SalahGfx\Desktop\Password Generator Files\Lock_closed_key_2-512.png'))
window.show()
sys.exit(app.exec_())
The files needed here