import sys
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QMainWindow, QLabel, QGridLayout, QWidget
from PyQt5.QtWidgets import QPushButton
from PyQt5.QtCore import QSize
import serial
#ser = serial.Serial('\\\\.\\COM7/dev/ttyUSB0') //This is my serial port address (Windows only need the COM declared, so I left only it)
#print(ser.name)
#ser.write(b'1')
#ser.close()
class Interface(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
pybutton = QPushButton('OK', self) //My button will contain the "OK" written
pybutton.clicked.connect(self.clickMethod) //The "OK" button can be clicked
pybutton.resize(100,32)
pybutton.move(100, 100) //Numbers referred to the position the widget has on the screen
self.setMinimumSize(QSize(300, 200))
self.setWindowTitle('MY WIDGET') //Title I want to see on my window's interface
self.show()
def clickMethod(self):
print('Clicked button.')
ser = serial.Serial('COM7')
print(ser.name)
ser.write(b'1')
ser.close()
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
mainWin = Interface()
mainWin.show()
sys.exit( app.exec_() )