jzh4n

PyQt5

Jun 20th, 2021
622
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from PyQt5.QtWidgets import QWidget, QApplication, QTextEdit
  2. from PyQt5 import uic, QtCore, QtGui, QtWidgets
  3. import sys, time, datetime, pymysql
  4. from threading import *
  5. import sched, time
  6.  
  7. from threading import Timer
  8.  
  9. class RepeatedTimer(object):
  10.     def __init__(self, interval, function, *args, **kwargs):
  11.         self._timer     = None
  12.         self.interval   = interval
  13.         self.function   = function
  14.         self.args       = args
  15.         self.kwargs     = kwargs
  16.         self.is_running = False
  17.         self.start()
  18.  
  19.     def _run(self):
  20.         self.is_running = False
  21.         self.start()
  22.         self.function(*self.args)
  23.  
  24.     def start(self):
  25.         if not self.is_running:
  26.             self._timer = Timer(self.interval, self._run)
  27.             self._timer.start()
  28.             self.is_running = True
  29.  
  30.     def stop(self):
  31.         self._timer.cancel()
  32.         self.is_running = False
  33.  
  34. class Ui_Form(object):
  35.  
  36.     # s = sched.scheduler(time.time, time.sleep)
  37.    
  38.     def do_something(self, sc):
  39.         sc.append("test")
  40.         # do your stuff
  41.         # s.enter(60, 1, do_something, (sc,))
  42.  
  43.     def setupUi(self, Form):
  44.         Form.setObjectName("Form")
  45.         Form.resize(431, 519)
  46.         self.grad = QtWidgets.QLabel(Form)
  47.         self.grad.setGeometry(QtCore.QRect(0, 0, 431, 521))
  48.         self.grad.setStyleSheet("background-color: rgb(0, 68, 206);")
  49.         self.grad.setText("")
  50.         self.grad.setObjectName("grad")
  51.         self.sendandrec = QtWidgets.QTextEdit(Form)
  52.         self.sendandrec.setGeometry(QtCore.QRect(20, 200, 351, 281))
  53.         font = QtGui.QFont()
  54.         font.setFamily("Century Gothic")
  55.         font.setPointSize(10)
  56.         self.sendandrec.setFont(font)
  57.         self.sendandrec.setObjectName("sendandrec")
  58.         self.label_2 = QtWidgets.QLabel(Form)
  59.         self.label_2.setGeometry(QtCore.QRect(240, 80, 81, 31))
  60.         self.label_2.setStyleSheet("font: 75 14pt \"Tahoma\";\n"
  61. "color: rgb(255, 255, 255);")
  62.         self.label_2.setObjectName("label_2")
  63.         self.pushButton = QtWidgets.QPushButton(Form)
  64.         self.pushButton.setGeometry(QtCore.QRect(280, 140, 91, 51))
  65.         font = QtGui.QFont()
  66.         font.setFamily("Arial")
  67.         font.setPointSize(14)
  68.         font.setBold(False)
  69.         font.setItalic(False)
  70.         font.setWeight(50)
  71.         self.pushButton.setFont(font)
  72.         self.pushButton.setStyleSheet("color: rgb(255, 255, 255);\n"
  73. "background-color: rgba(47, 47, 47,200);\n"
  74. "border: none;\n"
  75. "border-radius:25px;\n"
  76. "font: 14pt \"Arial\";")
  77.         self.pushButton.setObjectName("pushButton")
  78.         self.pushButton.clicked.connect(self.btnPushButtonOnClick)
  79.  
  80.         self.label = QtWidgets.QLabel(Form)
  81.         self.label.setGeometry(QtCore.QRect(10, 20, 371, 61))
  82.         font = QtGui.QFont()
  83.         font.setFamily("Century Gothic")
  84.         font.setPointSize(28)
  85.         self.label.setFont(font)
  86.         self.label.setStyleSheet("color: rgb(255, 255, 255);")
  87.         self.label.setObjectName("label")
  88.        
  89.         self.sendtext = QtWidgets.QLineEdit(Form)
  90.         self.sendtext.setGeometry(QtCore.QRect(20, 140, 251, 51))
  91.         font = QtGui.QFont()
  92.         font.setFamily("Century Gothic")
  93.         font.setPointSize(10)
  94.         self.sendtext.setFont(font)
  95.         self.sendtext.setStyleSheet("")
  96.         self.sendtext.setObjectName("sendtext")
  97.         # t1 = Thread(target=self.printing, args=())
  98.         # t1.start()
  99.  
  100.         self.retranslateUi(Form)
  101.         QtCore.QMetaObject.connectSlotsByName(Form)
  102.  
  103.         self.rt = RepeatedTimer(1, self.do_something, self.sendandrec)
  104.  
  105.     def btnPushButtonOnClick(self):
  106.         self.sendandrec.setText("Ditekan")
  107.  
  108.     def printing(self):
  109.         self.sendandrec.setText(self.sendandrec.toPlainText() +"\naaa")
  110.  
  111.  
  112.     def retranslateUi(self, Form):
  113.         _translate = QtCore.QCoreApplication.translate
  114.         Form.setWindowTitle(_translate("Form", "Form"))
  115.         self.label_2.setText(_translate("Form", "Tamu"))
  116.         self.pushButton.setText(_translate("Form", "Send"))
  117.         self.label.setText(_translate("Form", "konsultasi hukum"))
  118.  
  119.  
  120. if __name__ == "__main__":
  121.     import sys
  122.     app = QtWidgets.QApplication(sys.argv)
  123.     Form = QtWidgets.QWidget()
  124.     ui = Ui_Form()
  125.     ui.setupUi(Form)
  126.     Form.show()
  127.     # ui.rt.stop()
  128.     sys.exit(app.exec_())
  129.    
RAW Paste Data