Issue
I am using PyQt5 and I just want to add a text to my window.
I have not found any clear help about that on the web.
Do you know a simple way to add a text ?
Solution
Not sure if you really read the API but something like that should solve what you want to achieve.You could also inherit from QMainWindow or QDialog, or whatever you need. That's just an example from thousands of possibilities.
import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QLabel
from PyQt5.QtWidgets import QVBoxLayout
from PyQt5.QtWidgets import QWidget
class MainWindow(QWidget):
def __init__(self):
super(MainWindow, self).__init__()
self.layout = QVBoxLayout()
self.label = QLabel("My text")
self.layout.addWidget(self.label)
self.setWindowTitle("My Own Title")
self.setLayout(self.layout)
if __name__ == "__main__":
app = QApplication(sys.argv)
mw = MainWindow()
mw.show()
sys.exit(app.exec_())
The simplest example I could show you is that. I also added a title just in case it's what you meant, hope it helped you.
Answered By - yurisnm
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.