I am trying to create a textbox after selecting the textbox option from a combo box and adding an image after selecting the image option. I need help with this.
I know that self.line = QLineEdit will create a textbox and for a Combobox I can use combo.activated[str].connect(self.onChanged) to detect the change in combobox and call for the function but I dont know why it is not working after I put it in the onChanged function.
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
class Example(QMainWindow):
def __init__(self):
super().__init__()
combo = QComboBox(self)
combo.addItem("textbox")
combo.addItem("image")
combo.move(50, 50)
self.qlabel = QLabel(self)
self.qlabel.move(50,16)
combo.activated[str].connect(self.onChanged)
self.setGeometry(50,50,320,200)
self.setWindowTitle("Programme")
self.show()
def onChanged(self, text):
if text == 'textbox':
self.line = QLineEdit(self)
if text == 'image':
self.im = QPixmap("image.jpg")
self.label = QLabel()
self.label.setPixmap(self.im)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())