如何获取一个pyqt5窗口,而不是两个小Qinputdialong窗口
我的代码准确地完成了我想要的功能,通过QinputDialog从INT输入中生成一个随机密码。但是,我没有获得两个小弹出框,我想获得一个主窗口,其中一个带有QinputDialog字段的主窗口上有一个窗口上的按钮。我该如何实现?
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit
import random
class App(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle('Password Generator')
self.setGeometry(100,100, 400, 400)
self.num_pass()
self.length_pass()
self.execute()
self.show()
def num_pass(self):
self.num_value, okPressed = QInputDialog.getInt(self, "Password Amount:","Number:", 0, 1, 50, 1)
if okPressed:
print(self.num_value)
def length_pass(self):
self.len_value, okPressed = QInputDialog.getInt(self, "Password Length: ","Length:", 0, 1, 50, 1)
if okPressed:
print(self.len_value)
def execute(self):
char = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()-_,./?'
number = self.num_value
length = self.len_value
for password in range(self.num_value):
passwords = ''
for chars in range(self.len_value):
passwords += random.choice(char)
print(passwords)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())
My code does exactly what I want it to, generates a random password from int inputs through QInputDialog. But instead of getting two small pop-up boxes I want to get one main window that has the QInputDialog fields with the buttons on one window. How can I achieve this?
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit
import random
class App(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle('Password Generator')
self.setGeometry(100,100, 400, 400)
self.num_pass()
self.length_pass()
self.execute()
self.show()
def num_pass(self):
self.num_value, okPressed = QInputDialog.getInt(self, "Password Amount:","Number:", 0, 1, 50, 1)
if okPressed:
print(self.num_value)
def length_pass(self):
self.len_value, okPressed = QInputDialog.getInt(self, "Password Length: ","Length:", 0, 1, 50, 1)
if okPressed:
print(self.len_value)
def execute(self):
char = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890!@#$%^&*()-_,./?'
number = self.num_value
length = self.len_value
for password in range(self.num_value):
passwords = ''
for chars in range(self.len_value):
passwords += random.choice(char)
print(passwords)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以添加水平布局,并插入QBUTTON及其2个QinputDialog。并将您的按钮连接到execute()方法。
希望这会有所帮助。
You can add a horizontal layout, and insert a QButton and its 2 QInputDialog. And connect your button to the execute() method.
Hope this helps.