From anonymous, 2 Weeks ago, written in Python.
Embed
  1. import sys
  2.  
  3. from PyQt5.QtCore import Qt, QTimer
  4. from PyQt5.QtGui import QPixmap
  5. from PyQt5.QtWidgets import QApplication, QVBoxLayout, QWidget, QLineEdit, QLabel
  6.  
  7.  
  8. BASE_STYLE = """
  9.  background-color: lightgreen;
  10.  color: black;
  11.  padding: 20px;
  12.  border-radius: 20px;
  13. """
  14.  
  15.  
  16. def add_message(text, right=False, image=False):
  17.     message = QLabel()
  18.     if image:
  19.         message.setPixmap(QPixmap(text))
  20.     else:
  21.         message.setText(text)
  22.  
  23.     style = BASE_STYLE
  24.     if right:
  25.         style += "margin-left: 400px;"
  26.     else:
  27.         style += "margin-right: 400px;"
  28.     message.setStyleSheet(style)
  29.  
  30.     messages_layout.addWidget(message)
  31.  
  32.  
  33. def on_editing_finished():
  34.     text = input_box.text()
  35.     if not text:
  36.         return
  37.  
  38.     add_message(text)
  39.  
  40.     if text == 'img':
  41.         QTimer.singleShot(500, lambda: add_message('deltachat.png', right=True, image=True))
  42.     else:
  43.         QTimer.singleShot(500, lambda: add_message(text, right=True))
  44.  
  45.     input_box.clear()
  46.  
  47.  
  48. app = QApplication(sys.argv)
  49.  
  50. window = QWidget()
  51. window_layout = QVBoxLayout(window)
  52.  
  53. messages = QWidget()
  54. messages_layout = QVBoxLayout(messages)
  55.  
  56. window_layout.addWidget(messages)
  57.  
  58. window_layout.addStretch()
  59.  
  60. input_box = QLineEdit()
  61. input_box.editingFinished.connect(on_editing_finished)
  62. window_layout.addWidget(input_box)
  63.  
  64. window.show()
  65. app.exec_()
  66.