Last active
November 2, 2018 18:49
-
-
Save eyllanesc/5884239ffec38da4ade88946f2e2b84f to your computer and use it in GitHub Desktop.
Example 53122557
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PyQt5 import QtWidgets | |
class Dialog(QtWidgets.QDialog): | |
def __init__(self, parent=None): | |
super(Dialog, self).__init__(parent=None) | |
self.user_le = QtWidgets.QLineEdit() | |
self.pass_le = QtWidgets.QLineEdit(echoMode=QtWidgets.QLineEdit.Password) | |
buttonBox = QtWidgets.QDialogButtonBox() | |
buttonBox.setStandardButtons(QtWidgets.QDialogButtonBox.Cancel|QtWidgets.QDialogButtonBox.Ok) | |
buttonBox.accepted.connect(self.accept) | |
buttonBox.rejected.connect(self.reject) | |
lay = QtWidgets.QFormLayout(self) | |
lay.addRow("Username: ", self.user_le) | |
lay.addRow("Password: ", self.pass_le) | |
lay.addRow(buttonBox) | |
def get_results(self): | |
return self.user_le.text(), self.pass_le.text() | |
class Widget(QtWidgets.QWidget): | |
def __init__(self, parent=None): | |
super(Widget, self).__init__(parent=None) | |
self.user_label = QtWidgets.QLabel() | |
self.pass_label = QtWidgets.QLabel() | |
lay = QtWidgets.QFormLayout(self) | |
lay.addRow("Username: ", self.user_label) | |
lay.addRow("Password: ", self.pass_label) | |
self.resize(640, 480) | |
def open_dialog(self): | |
# open dialog | |
w = Dialog() | |
if w.exec_() == QtWidgets.QDialog.Accepted: | |
username, password = w.get_results() | |
self.user_label.setText(username) | |
self.pass_label.setText(password) | |
if __name__ == '__main__': | |
import sys | |
app = QtWidgets.QApplication(sys.argv) | |
w = Widget() | |
w.show() | |
w.open_dialog() | |
sys.exit(app.exec_()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment