document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import sys
  2. from PyQt5 import QtCore, QtWidgets
  3. from PyQt5.QtWidgets import QMainWindow, QLabel, QGridLayout, QWidget
  4. from PyQt5.QtWidgets import QPushButton
  5. from PyQt5.QtCore import QSize
  6.  
  7. import serial
  8.  
  9. #ser = serial.Serial('\\\\.\\COM7/dev/ttyUSB0') //This is my serial port address (Windows only need the COM declared, so I left only it)
  10. #print(ser.name)
  11. #ser.write(b'1')
  12. #ser.close()
  13.  
  14.  
  15. class Interface(QWidget):
  16.  
  17. def __init__(self):
  18. super().__init__()
  19.  
  20. self.initUI()
  21.  
  22.  
  23. def initUI(self):
  24. pybutton = QPushButton('OK', self) //My button will contain the "OK" written
  25. pybutton.clicked.connect(self.clickMethod) //The "OK" button can be clicked
  26. pybutton.resize(100,32)
  27. pybutton.move(100, 100) //Numbers referred to the position the widget has on the screen
  28. self.setMinimumSize(QSize(300, 200))
  29.  
  30. self.setWindowTitle('MY WIDGET') //Title I want to see on my window's interface
  31. self.show()
  32.  
  33. def clickMethod(self):
  34. print('Clicked button.')
  35. ser = serial.Serial('COM7')
  36. print(ser.name)
  37. ser.write(b'1')
  38. ser.close()
  39.  
  40.  
  41. if __name__ == "__main__":
  42. app = QtWidgets.QApplication(sys.argv)
  43. mainWin = Interface()
  44. mainWin.show()
  45. sys.exit( app.exec_() )
');