call a code with a button in Pyqt

0

I'm working with Pyqt and I have my window with 3 buttons. The first and second buttons I want to give them shares. The actions that I need is that they initiate other codes.   link There are both programs. Pantalla.py is the pyqt and I need the first button to execute the test code! Probe placing import test at the start of the program but I run it simultaneously when I run pantalla.py

Use Pyqt4 and python 2.7

   def __init__(self, parent=None):
      super(Form, self).__init__(parent)
      layout = QVBoxLayout()
      #Marketplace
      self.b1 = QPushButton("Market Places")
      self.b1.setCheckable(True)
      self.b1.clicked.connect(lambda:self.whichbtn(self.b1))
      self.b1.clicked.connect(self."test.py")

I know it's badly written but it's a way of graphing what I'm looking for! Greetings

    
asked by Martin Bouhier 02.11.2017 в 18:13
source

1 answer

1

This way the code reads my file1.py and executes it when I click on the button. Greetings

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import QtGui, QtCore
from file1 import main

class Form(QDialog):
   def __init__(self, parent=None):
      super(Form, self).__init__(parent)
      layout = QVBoxLayout()
      #Marketplace
      self.b1 = QPushButton("Inventory Sources")
      self.b1.setCheckable(True)
      self.b1.clicked.connect(lambda:self.whichbtn(self.b1))
      self.b1.clicked.connect(self.btnstate)
      layout.addWidget(self.b1)
      self.setLayout(layout)

      #Inventory
      self.b2 = QPushButton("Not In Inv-Sources Marketplaces")
      self.b2.setCheckable(True)
      self.b2.clicked.connect(lambda:self.whichbtn(self.b2))
      self.b2.clicked.connect(self.aaa)
      layout.addWidget(self.b2)
      self.setLayout(layout)

      #Exit 
      self.b4 = QPushButton("EXIT")
      self.b4.setDefault(True)
      self.b4.clicked.connect(lambda:self.whichbtn(self.b4))
      layout.addWidget(self.b4)
      self.b4.clicked.connect(QtCore.QCoreApplication.instance().quit)
      self.setGeometry(300, 300, 250, 150)
      self.setWindowTitle("AOL Optimizations")
      self.setWindowIcon(QIcon('logo.png'))

   def aaa (self):
      main()
   def btnstate(self):
      if self.b1.isChecked():
         print "button pressed"
      else:
         print "button released"

   def whichbtn(self,b):
      print "clicked button Marketplacements Optimizations "

def car():
   app = QApplication(sys.argv)
   ex = Form()
   ex.show()
   sys.exit(app.exec_())

if __name__ == '__main__':
   car()
    
answered by 02.11.2017 в 20:24