Answer the question
In order to leave comments, you need to log in
PyQt write to lineEdit on button click?
# -*- coding: utf-8 -*-
from PyQt5 import QtWidgets, uic
import sys
class MyWindow(QtWidgets.QWidget):
def __init__(self, parent = None):
QtWidgets.QWidget.__init__(self, parent)
Form, Base = uic.loadUiType("window.ui")
self.ui = Form()
self.ui.setupUi(self)
self.ui.lineEdit.setText("Text") # Пример №1
self.ui.btnQuit.clicked.connect(self.ui.lineEdit.setText("Text")) # Пример №2
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
window = MyWindow()
window.show()
sys.exit(app.exec_())
Answer the question
In order to leave comments, you need to log in
It is possible like this:
or bind to a method
# -*- coding: utf-8 -*-
from PyQt5 import QtWidgets, uic
import sys
class MyWindow(QtWidgets.QWidget):
def __init__(self, parent = None):
QtWidgets.QWidget.__init__(self, parent)
Form, Base = uic.loadUiType("window.ui")
self.ui = Form()
self.ui.setupUi(self)
self.ui.lineEdit.setText("Text") # Пример №1
self.ui.btnQuit.clicked.connect(self.setmytext)) # Пример №2 Внимательно со скобками, нам нужно
#передать метод, но не результат его выполнения!
def setmytext(self):
self.ui.lineEdit.setText("Text")
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
window = MyWindow()
window.show()
sys.exit(app.exec_())
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question