pythonpyqtpyqt5qwidget

Render python list in pyqt Qwidget


So i have a problem writing what i have as list in a python code into my Qwidget , what i want is : as i have a list of tweets , when i click on the button i want my code to write what i have in a list in the Qwidget i don't know what to use for the writing part , i thought of using QPlainTextEdit which i think is not right , can you give me an idea of what to use and how ? here is my code

import sys
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import *
import gettweet
app = QApplication.instance()
if not app:
    app = QApplication(sys.argv)
widget = QWidget()
get = QPushButton(widget)
get.setText("Get tweet")
get.move(64,32)
widget.setGeometry(50,50,800,600)
widget.setWindowTitle("Sentiments tweets")
QtWidgets.QPlainTextEdit(widget).setGeometry(300,0 , 500,600)
def window() :
    get.clicked.connect(button1_clicked)
    widget.show()
    app.exec_()


def button1_clicked() :
    tweets = gettweet.get()
    for i in tweets :
        pass



if __name__ == '__main__':
   window()

Solution

  • i do not know if you want it like this but i made the application put the items that are in the list to the QPlainTextEdit.

    you should edit and fix the code to make it like what you want because i edited it.

    
    from re import I
    import sys
    from PyQt5 import QtWidgets
    from PyQt5.QtWidgets import *
    
    
    app = QApplication.instance()
    if not app:
        app = QApplication(sys.argv)
    widget = QWidget()
    
    
    def button1_clicked() :
        tweets = ["1","2"]
        for i in tweets :
            MyQPlainTextEdit.setPlainText(i)
    
    get = QPushButton(widget)
    get.setText("Get tweet")
    get.move(64,32)
    widget.setGeometry(50,50,800,600)
    widget.setWindowTitle("Sentiments tweets")
    
    MyQPlainTextEdit = QtWidgets.QPlainTextEdit(widget)
    MyQPlainTextEdit.setGeometry(300,0 , 500,600)
    
    def window() :
        get.clicked.connect(button1_clicked)
        widget.show()
        app.exec_()
    
    
    if __name__ == '__main__':
       window()
    
    

    and i will give you an idea

    you can create a container and put in it a lot of QPlainTextEdit like you have of tweets for example you have 10 tweets and you want to show them you can make it like this:

    from PyQt5 import QtWidgets
    from PyQt5 import QtGui
    from PyQt5 import QtCore
    
    class ForExample:
    
        Tweets = ["1","2","3"]
    
        def __init__(self):
            self.Application = QtWidgets.QApplication([])
            self.Window = QtWidgets.QWidget()
            self.Window.resize(800,500)
            self.WindowLayout = QtWidgets.QGridLayout()
    
            self.ScrollArea = QtWidgets.QScrollArea()
            self.ScrollArea.setWidgetResizable(True)
    
            self.GroupBox = QtWidgets.QGroupBox()
            self.GroupBoxLayout = QtWidgets.QGridLayout()
            self.GroupBox.setLayout(self.GroupBoxLayout)
    
            self.ScrollArea.setWidget(self.GroupBox)
    
            def FunctionToDoTheWord():
                for i in range(len(self.Tweets)):
                    self.GroupBoxLayout.addWidget(QtWidgets.QPlainTextEdit(self.Tweets[i]))
    
            self.ButtonToShowTheTweets = QtWidgets.QPushButton("Show Tweets")
            self.ButtonToShowTheTweets.clicked.connect(FunctionToDoTheWord)
            
            
            self.WindowLayout.addWidget(self.ScrollArea)
            self.WindowLayout.addWidget(self.ButtonToShowTheTweets)
    
            self.Window.setLayout(self.WindowLayout)
            self.Window.show()
            self.Application.exec()
    
    ForExample()
    
    

    try this and tell me.