Astor_5643

pyqt_test

Jan 20th, 2022 (edited)
323
238 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import sys
  2.  
  3. from PyQt5.QtCore import Qt
  4. from PyQt5.QtWidgets import (
  5.     QApplication,
  6.     QCheckBox,
  7.     QComboBox,
  8.     QDateEdit,
  9.     QDateTimeEdit,
  10.     QDial,
  11.     QDoubleSpinBox,
  12.     QFontComboBox,
  13.     QLabel,
  14.     QLCDNumber,
  15.     QLineEdit,
  16.     QMainWindow,
  17.     QProgressBar,
  18.     QPushButton,
  19.     QRadioButton,
  20.     QSlider,
  21.     QSpinBox,
  22.     QTimeEdit,
  23.     QVBoxLayout,
  24.     QWidget,
  25. )
  26.  
  27. class MainWindow(QMainWindow):
  28.  
  29.     def __init__(self):
  30.         super(MainWindow, self).__init__()
  31.  
  32.         self.setWindowTitle("My App")
  33.  
  34.         widget = QLineEdit()
  35.         widget.setMaxLength(10)
  36.         widget.setPlaceholderText("Enter your text")
  37.  
  38.         widget.returnPressed.connect(self.return_pressed)
  39.         widget.selectionChanged.connect(self.selection_changed)
  40.         widget.textChanged.connect(self.text_changed)
  41.         widget.textEdited.connect(self.text_edited)
  42.  
  43.         self.setCentralWidget(widget)
  44.  
  45.  
  46.     def return_pressed(self):
  47.         self.centralWidget().setText("BOOM!")
  48.  
  49.     def selection_changed(self):
  50.         print(self.centralWidget().selectedText())
  51.  
  52.     def text_changed(self, s):
  53.          print(s)
  54.  
  55.     def text_edited(self, s):
  56.         print(s)
  57.  
  58. app = QApplication(sys.argv)
  59. window = MainWindow()
  60. window.show()
  61.  
  62. app.exec()
RAW Paste Data Copied