![]() |
How to run a script within a pyqt window - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: How to run a script within a pyqt window (/thread-4382.html) |
How to run a script within a pyqt window - finswitch - Aug-12-2017 Hi, I have written a pyQt script for a window with some button indicators in it. Within this window I have written a second section which monitors the th inputs of my raspberry pi and changes the colours of my indicators depending on what input is on. However I am struggling to get the second script to run within the window without it taking over the window or running but not changing the colours if the indicators. I know the second script works as I have created a test button and to run the script when pressed and it changes the colours of the indicators fine. How can I run my input monitoring script within my pyQt window while still being able to interact with the window as well as it live changing the colours of the indicators when input turn on and off. Thanks in advance. import sys from PyQt4 import QtGui, QtCore from PyQt4.QtGui import * import subprocess import RPi.GPIO as GPIO GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(10, GPIO.IN) GPIO.setup(11, GPIO.IN) GPIO.setup(12, GPIO.IN) #state_GPIO10 = GPIO.input(10) #state_GPIO11 = GPIO.input(11) #state_GPIO12 = GPIO.input(12) class Window(QtGui.QMainWindow): def __init__(self): super(Window, self).__init__() self.initUI() def initUI(self): self.setGeometry(50, 50, 800, 480) self.setWindowTitle("Master Window") self.home() self.GPIO_control() def home(self): global button global button1 global button2 global button3 button = QtGui.QPushButton("Quit", self) button.clicked.connect(self.close_application) button.resize(100, 50) button.move(700, 430) button1 = QtGui.QPushButton("RUNNING", self) button1.resize(200, 50) button1.move(50, 215) button2 = QtGui.QPushButton("MATERIAL REQUIRED", self) button2.resize(200, 50) button2.move(300, 215) button3 = QtGui.QPushButton("MAINTENANCE REQUIRED", self) button3.resize(200, 50) button3.move(550, 215) # button4 = QtGui.QPushButton("TEST", self) # button4.clicked.connect(self.GPIO_control) # button4.resize(200, 50) # button4.move(300, 320) self.showFullScreen() def close_application(self): close_choice = QtGui.QMessageBox.question(self, 'Double Checker', "Are you sure you want to quit?", QtGui.QMessageBox.Yes | QtGui.QMessageBox.No) if close_choice == QtGui.QMessageBox.Yes: sys.exit() else: pass def GPIO_control(self): while True: if GPIO.input(10): print "INPUT 10" button1.setStyleSheet("background-color: red") button2.setStyleSheet("background-color: none") button3.setStyleSheet("background-color: none") elif GPIO.input(11): print "input 11" button1.setStyleSheet("background-color: none") button2.setStyleSheet("background-color: red") button3.setStyleSheet("background-color: none") elif GPIO.input(12): print "input 12" button1.setStyleSheet("background-color: none") button2.setStyleSheet("background-color: none") button3.setStyleSheet("background-color: red") else: button1.setStyleSheet("background-color: none") button2.setStyleSheet("background-color: none") button3.setStyleSheet("background-color: none") else: pass def main(): app = QtGui.QApplication(sys.argv) GUI = Window() sys.exit(app.exec_()) main() RE: How to run a script within a pyqt window - hbknjr - Aug-12-2017 Qthread can be helpful in this scenario. By using threading you can monitor the input state and simultaneously retain control on main window. |