Hey everybody,
if´ve managed to get PyQt5 to work, it shows the menu but i`m not able to store the info in a variable, has someone an idea?
import sys
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QMainWindow, QWidget, QLabel, QLineEdit
from PyQt5.QtWidgets import QPushButton
from PyQt5.QtCore import QSize
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setMinimumSize(QSize(320, 140))
self.setWindowTitle("PyQt Line Edit example (textfield) - pythonprogramminglanguage.com")
self.nameLabel = QLabel(self)
self.nameLabel.setText('Name:')
self.line = QLineEdit(self)
self.line.move(80, 20)
self.line.resize(200, 32)
self.nameLabel.move(20, 20)
pybutton = QPushButton('OK', self)
pybutton.clicked.connect(self.clickMethod)
pybutton.resize(200,32)
pybutton.move(80, 60)
def clickMethod(self):
output = ('Your name: ' + self.line.text())
self.close()
if IN[0]:
app = QtWidgets.QApplication(sys.argv)
mainWin = MainWindow()
mainWin.show()
sys.exit(app.exec_())
else:
output = ("Eingang IN[0] auf True setzten! ")
OUT = output
Hello,
add an attribute in your class
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('Python.Included')
import Python.Included as pyInc
path_py3_lib = pyInc.Installer.EmbeddedPythonHome
sys.path.append(path_py3_lib + r'\Lib\site-packages')
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QMainWindow, QWidget, QLabel, QLineEdit
from PyQt5.QtWidgets import QPushButton
from PyQt5.QtCore import QSize
class MainWindow(QMainWindow):
def __init__(self):
self.output = None
QMainWindow.__init__(self)
self.setMinimumSize(QSize(320, 140))
self.setWindowTitle("PyQt Line Edit example (textfield) - pythonprogramminglanguage.com")
self.nameLabel = QLabel(self)
self.nameLabel.setText('Name:')
self.line = QLineEdit(self)
self.line.move(80, 20)
self.line.resize(200, 32)
self.nameLabel.move(20, 20)
pybutton = QPushButton('OK', self)
pybutton.clicked.connect(self.clickMethod)
pybutton.resize(200,32)
pybutton.move(80, 60)
def clickMethod(self):
self.output = ('Your name: ' + self.line.text())
self.close()
if IN[0]:
app = QtWidgets.QApplication(sys.argv)
mainWin = MainWindow()
mainWin.show()
app.exec_()
output = mainWin.output
else:
output = ("Eingang IN[0] auf True setzten! ")
OUT = output
3 Likes
I can run using PyQt5, however when I change the code to the latest version PyQt6, it fails to run
P.S. I have installed both PyQt5 & 6 in my computer
try this
import sys
import clr
clr.AddReference('ProtoGeometry')
from Autodesk.DesignScript.Geometry import *
clr.AddReference('Python.Included')
import Python.Included as pyInc
path_py3_lib = pyInc.Installer.EmbeddedPythonHome
sys.path.append(path_py3_lib + r'\Lib\site-packages')
from PyQt6.QtWidgets import QMainWindow, QWidget, QLabel, QLineEdit, QApplication
from PyQt6.QtWidgets import QPushButton
from PyQt6.QtCore import QSize
class MainWindow(QMainWindow):
def __init__(self):
self.output = None
QMainWindow.__init__(self)
self.setMinimumSize(QSize(320, 140))
self.setWindowTitle("PyQt Line Edit example (textfield) - pythonprogramminglanguage.com")
self.nameLabel = QLabel(self)
self.nameLabel.setText('Name:')
self.line = QLineEdit(self)
self.line.move(80, 20)
self.line.resize(200, 32)
self.nameLabel.move(20, 20)
pybutton = QPushButton('OK', self)
pybutton.clicked.connect(self.clickMethod)
pybutton.resize(200,32)
pybutton.move(80, 60)
def clickMethod(self):
self.output = ('Your name: ' + self.line.text())
self.close()
if IN[0]:
app = QApplication(sys.argv)
mainWin = MainWindow()
mainWin.show()
app.exec()
output = mainWin.output
else:
output = ("Eingang IN[0] auf True setzten! ")
OUT = output
same
while using PyQt5, it works:
but nevermind I will stick with PyQt5
try using the Dynamo path lib, need to install packages in this directory
2 Likes