PyQt class inheritance - python

I am having troubles to understand class inheritance with Python/PyQt. I have a MainWindow and a Popup QWidget. I want to interact with the self.label1 of the MainWindow after the QWidget was opened in a pop up window but I don't know how to do it. I know only the other way around, to reach all widgets from the popup Window inside MainWindow but not vice versa.
Here is an example, self.label1 of MainWindow should get another text after MyPopup opens in a new window:
import sys
from PyQt4.Qt import *
class MyPopup(QWidget):
def __init__(self):
QWidget.__init__(self)
# I want to change the lable1 of MainWindow
self.cw.label1.setText('hello')
class MainWindow(QMainWindow):
def __init__(self, *args):
QMainWindow.__init__(self, *args)
self.cw = QWidget(self)
self.setCentralWidget(self.cw)
self.btn1 = QPushButton("Click me", self.cw)
self.btn1.setGeometry(QRect(50, 50, 100, 30))
self.label1 = QLabel("No Commands running", self.cw)
self.connect(self.btn1, SIGNAL("clicked()"), self.doit)
self.w = None
def doit(self):
self.w = MyPopup()
self.w.setGeometry(QRect(100, 100, 400, 200))
self.w.show()
if __name__ == "__main__":
app = QApplication(sys.argv)
myapp = MainWindow()
myapp.show()
sys.exit(app.exec_())

You need to pass the main window as a parameter to the constructor of MyPopup, try this:
import sys
from PyQt4.Qt import *
class MyPopup(QWidget):
def __init__(self, mainWindow):
QWidget.__init__(self)
# use the mainWindow passed as parameter
mainWindow.label1.setText('hello')
class MainWindow(QMainWindow):
def __init__(self, *args):
QMainWindow.__init__(self, *args)
self.cw = QWidget(self)
self.setCentralWidget(self.cw)
self.btn1 = QPushButton("Click me", self.cw)
self.btn1.setGeometry(QRect(50, 50, 100, 30))
self.label1 = QLabel("No Commands running", self.cw)
self.connect(self.btn1, SIGNAL("clicked()"), self.doit)
self.w = None
def doit(self):
self.w = MyPopup(self) #when creating the popup pass in the main window
self.w.setGeometry(QRect(100, 100, 400, 200))
self.w.show()
if __name__ == "__main__":
app = QApplication(sys.argv)
myapp = MainWindow()
myapp.show()
sys.exit(app.exec_())

This is the prior answer from Alvaro Fuentes, with the minor updates necessary for PyQt5.
import sys
from PyQt5.Qt import *
class MyPopup(QWidget):
def __init__(self, mainwin):
QWidget.__init__(self)
# I want to change the lable1 of MainWindow
mainwin.label1.setText('hello')
class MainWindow(QMainWindow):
def __init__(self, *args):
QMainWindow.__init__(self, *args)
self.cw = QWidget(self)
self.setCentralWidget(self.cw)
self.btn1 = QPushButton("Click me", self.cw)
self.btn1.setGeometry(QRect(50, 50, 100, 30))
self.label1 = QLabel("No Commands running", self.cw)
self.btn1.clicked.connect(self.doit)
self.w = None
def doit(self):
self.w = MyPopup(self)
self.w.setGeometry(QRect(100, 100, 400, 200))
self.w.show()
if __name__ == "__main__":
app = QApplication(sys.argv)
myapp = MainWindow()
myapp.show()
sys.exit(app.exec_())

Related

PyQt5 retrieving ID and values from multiple Buttons created in an open loop [duplicate]

This question already has answers here:
How to determine which widget emitted the signal
(1 answer)
How do I assert the identity of a PyQt5 signal?
(2 answers)
Closed 2 years ago.
I'm trying to create buttons (QPushButtons) based on an entry (QLineEdit). The idea is that I want the user to be able to create as many buttons as wanted, simply by adding new text in the entry box and by then pressing "Add Label" (see picture below).
While I'm able to do this, I can't for now retrieve the label value of each of these buttons, since the procedure I use erases all the previous values (I can only retrieve the last value entered). I'd like to be able to print each specific Label Value when clicking each button.
My code is below:
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QLineEdit
import sys
class MyWindow(QMainWindow):
def __init__(self):
super(MyWindow, self).__init__()
self.setGeometry(100, 100, 1500, 1500)
self.setWindowTitle("My Program")
self.labelButtons = [] # List of all the buttons displaying labels
self.eraseButtons = [] # List of all the buttons displaying "X"
self.Yposition = 50
self.initUI()
def initUI(self):
self.labelEntry = QLineEdit(self)
self.labelEntry.move(50, self.Yposition)
self.labelEntry.resize(300, 40)
self.addLabelButton = QPushButton(self)
self.addLabelButton.setText("Add Label")
self.addLabelButton.move(400, self.Yposition)
self.addLabelButton.resize(300, 40)
self.addLabelButton.clicked.connect(self.addNewLabel)
def addNewLabel(self):
self.Yposition += 50
self.newLabelName = self.labelEntry.text()
self.labelButtons.append(self.createButtonLabel(self.newLabelName))
self.eraseButtons.append(self.eraseButtonLabel())
self.updatelabels()
def createButtonLabel(self, labelname):
self.button = QPushButton(self)
self.button.setText(str(labelname))
self.button.resize(300, 40)
self.button.move(50, self.Yposition)
self.button.clicked.connect(self.printbutton)
return self.button
def eraseButtonLabel(self):
self.buttonErase = QPushButton(self)
self.buttonErase.setText("X")
self.buttonErase.resize(40, 40)
self.buttonErase.move(360, self.Yposition)
self.buttonErase.clicked.connect(self.printbutton)
return self.buttonErase
def updatelabels(self):
for button in self.labelButtons:
button.show()
for button in self.eraseButtons:
button.show()
def printbutton(self):
print(self.button.text())
if __name__ == '__main__':
app = QApplication(sys.argv)
win = MyWindow()
win.show()
sys.exit(app.exec_())
<!-- end snippet -->
Using Google pyqt clicked event I found you have to use
def printbutton(self):
widget = self.sender()
print(widget.text())
ZetCode: Events and signals in PyQt5
EDIT:
As for erease button - you should get button from createButtonLabel and send it to eraseButtonLabel
labelbutton = self.createButtonLabel(self.newLabelName)
erasebutton = self.eraseButtonLabel(labelbutton)
and you can use lambda to assing function with argument
def eraseButtonLabel(self, labelbutton):
# ... code ...
self.buttonErase.clicked.connect(lambda: self.erasebutton(labelbutton))
and function should get this argument
def erasebutton(self, button):
widget = self.sender()
print('clicked:', widget.text())
print(' erase:', button.text())
Or you can assing button to own variable in buttonErase
def eraseButtonLabel(self, labelbutton):
# ... code ...
self.buttonErase.assigned_button = labelbutton
self.buttonErase.clicked.connect(self.erasebutton)
and use it in function
def erasebutton(self):
widget = self.sender()
print('clicked:', widget.text())
print(' erase:', widget.assigned_button.text())
Full code which uses both methods at the same time but you need only one method.
from PyQt5.QtWidgets import *
import sys
class MyWindow(QMainWindow):
def __init__(self):
super(MyWindow, self).__init__()
self.setGeometry(100, 100, 1500, 1500)
self.setWindowTitle("My Program")
self.labelButtons = [] # List of all the buttons displaying labels
self.eraseButtons = [] # List of all the buttons displaying "X"
self.Yposition = 50
self.initUI()
def initUI(self):
self.labelEntry = QLineEdit(self)
self.labelEntry.move(50, self.Yposition)
self.labelEntry.resize(300, 40)
self.addLabelButton = QPushButton(self)
self.addLabelButton.setText("Add Label")
self.addLabelButton.move(400, self.Yposition)
self.addLabelButton.resize(300, 40)
self.addLabelButton.clicked.connect(self.addNewLabel)
def addNewLabel(self):
self.Yposition += 50
self.newLabelName = self.labelEntry.text()
labelbutton = self.createButtonLabel(self.newLabelName)
erasebutton = self.eraseButtonLabel(labelbutton)
self.labelButtons.append(labelbutton)
self.eraseButtons.append(erasebutton)
self.updatelabels()
def createButtonLabel(self, labelname):
self.button = QPushButton(self)
self.button.setText(str(labelname))
self.button.resize(300, 40)
self.button.move(50, self.Yposition)
self.button.clicked.connect(self.printbutton)
return self.button
def eraseButtonLabel(self, labelbutton):
self.buttonErase = QPushButton(self)
self.buttonErase.setText("X")
self.buttonErase.resize(40, 40)
self.buttonErase.move(360, self.Yposition)
self.buttonErase.assigned_button = labelbutton
self.buttonErase.clicked.connect(lambda: self.erasebutton(labelbutton))
#self.buttonErase.clicked.connect(self.erasebutton)
return self.buttonErase
def updatelabels(self):
for button in self.labelButtons:
button.show()
for button in self.eraseButtons:
button.show()
def printbutton(self):
print('clicked:', self.sender().text())
def erasebutton(self, button):
widget = self.sender()
print('clicked:', widget.text())
print(' erase:', button.text())
print(' erase:', widget.assigned_button.text())
if __name__ == '__main__':
app = QApplication(sys.argv)
win = MyWindow()
win.show()
sys.exit(app.exec_())
EDIT:
Other method is to create own widget which has both buttons labelbutton and erasebutton and then erasebutton has direct access only to own labelbutton.
BTW: and for similar reason I would keep buttons as pairs
self.buttons.append([labelbutton, erasebutton])
instead of separted lists
self.labelButtons.append(labelbutton)
self.eraseButtons.append(erasebutton)
Example in which I create own widget.
from PyQt5.QtWidgets import *
import sys
class MyWidget(QWidget):
def __init__(self, parent, labelname, *args, **kwargs):
super().__init__(parent, *args, **kwargs)
self.resize(350, 40)
self.labelButton = QPushButton(self)
self.labelButton.setText(str(labelname))
self.labelButton.resize(300, 40)
self.labelButton.move(0, 0)
self.labelButton.clicked.connect(self.printbutton)
self.buttonErase = QPushButton(self)
self.buttonErase.setText("X")
self.buttonErase.resize(40, 40)
self.buttonErase.move(310, 0)
self.buttonErase.clicked.connect(self.erasebutton)
self.show()
def printbutton(self):
print('clicked:', self.labelButton.text())
def erasebutton(self):
print('clicked:', self.buttonErase.text())
print(' erase:', self.labelButton.text())
class MyWindow(QMainWindow):
def __init__(self):
super(MyWindow, self).__init__()
self.setGeometry(100, 100, 1500, 1500)
self.setWindowTitle("My Program")
self.widgets = []
self.Yposition = 50
self.initUI()
def initUI(self):
self.labelEntry = QLineEdit(self)
self.labelEntry.move(50, self.Yposition)
self.labelEntry.resize(300, 40)
self.addLabelButton = QPushButton(self)
self.addLabelButton.setText("Add Label")
self.addLabelButton.move(400, self.Yposition)
self.addLabelButton.resize(300, 40)
self.addLabelButton.clicked.connect(self.addNewLabel)
def addNewLabel(self):
self.Yposition += 50
text = self.labelEntry.text()
widget = MyWidget(self, text)
widget.move(50, self.Yposition)
self.widgets.append(widget)
if __name__ == '__main__':
app = QApplication(sys.argv)
win = MyWindow()
win.show()
sys.exit(app.exec_())

How to update QWidget's content?

There is a QWidget, which is called with the button "Start" in the main widget.
It shows some text, which should be updated every minute during the work of the QWidget.
How can I make this infinity updating within this code?
class ExampleWidget(QWidget):
def __init__(self, parent=None):
super().__init__()
self.setWindowTitle('Example Widget ScrollArea')
self.initUi()
def initUi(self):
area = QScrollArea(self)
area.setWidgetResizable(True)
self.scrollAreaWidgetContents = QLabel(some_text, self)
area.setWidget(self.scrollAreaWidgetContents)
button = QPushButton("Close")
button.clicked.connect(self.goMainWindow)
layoutV = QVBoxLayout()
layoutV.addWidget(area)
layoutV.addWidget(button)
self.setLayout(layoutV)
def goMainWindow(self):
self.hide()
def sizeHint(self):
return QSize(400, 200)
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
start_main_button = QPushButton('Start', self)
start_main_button.move(40, 40)
start_main_button.clicked.connect(self.start)
self.setGeometry(300, 300, 290, 150)
self.setWindowTitle('Test')
def start(self):
global some_text
some_text = 'some text'
self.result_widget = ExampleWidget()
self.result_widget.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
One of my tries:
def start(self):
global some_text
some_text = 'some text'
self.result_widget = ExampleWidget()
self.result_widget.show()
i = 0
while True:
i+=1
some_text+=str(i)
self.result_widget = ExampleWidget()
self.result_widget.show()
Forget the global variables because they are considered bad practice, on the other hand in a GUI you should avoid having loops that consume a lot of time, and in your case a while True blocks the GUI. In Qt if you want to do periodic tasks you must use a QTimer:
from PyQt5 import QtCore, QtWidgets
class ExampleWidget(QtWidgets.QWidget):
def __init__(self, parent=None):
super().__init__()
self.setWindowTitle('Example Widget ScrollArea')
self.initUi()
def initUi(self):
area = QtWidgets.QScrollArea()
area.setWidgetResizable(True)
self.scrollAreaWidgetContents = QtWidgets.QLabel("some_text")
area.setWidget(self.scrollAreaWidgetContents)
button = QtWidgets.QPushButton("Close")
button.clicked.connect(self.hide)
layoutV = QtWidgets.QVBoxLayout(self)
layoutV.addWidget(area)
layoutV.addWidget(button)
def update_text(self, text):
# update the text
self.scrollAreaWidgetContents.setText(text)
def sizeHint(self):
return QtCore.QSize(400, 200)
class MainWindow(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
start_main_button = QtWidgets.QPushButton('Start', self)
start_main_button.move(40, 40)
start_main_button.clicked.connect(self.start)
self.setGeometry(300, 300, 290, 150)
self.setWindowTitle('Test')
self.result_widget = ExampleWidget()
self.timer = QtCore.QTimer(self, interval=60*1000)
self.timer.timeout.connect(self.on_timeout)
self.counter = 0
self.initial_text = "some_text"
def on_timeout(self):
# this method will be called every 60 * 1000 ms
self.initial_text += str(self.counter)
self.result_widget.update_text(self.initial_text)
self.counter += 1
#QtCore.pyqtSlot()
def start(self):
self.result_widget.show()
# start timer
self.timer.start()
if __name__ == '__main__':
import sys
app = QtWidgets.QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())

maximum recursion depth exceeded in python multiple dialog

# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtGui, QtCore
class Window_Test3(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
global progress_flag
**self.Next_Window = Window_Test1() # Return Window_Test1() but RuntimeError: maximum recursion depth exceeded**
self.setWindowFlags(QtCore.Qt.CustomizeWindowHint|QtCore.Qt.WindowTitleHint|QtCore.Qt.WindowMaximizeButtonHint)
self.setGeometry(0, 0, 800,480)
self.setWindowTitle('TEST PROCESSING')
quit = QtGui.QPushButton('Close', self)
quit.setGeometry(10, 10, 60, 35)
test = QtGui.QPushButton('TEST 3', self)
test.setGeometry(100, 200, 200, 100)
self.connect(quit, QtCore.SIGNAL('clicked()'),self.reject)
self.connect(test, QtCore.SIGNAL('clicked()'), self.nextWindow)
def nextWindow(self):
self.Next_Window.show()
class Window_Test2(QtGui.QDialog):
def __init__(self):
QtGui.QWidget.__init__(self)
global progress_flag
self.Window3 = Window_Test3()
self.setWindowFlags(QtCore.Qt.CustomizeWindowHint|QtCore.Qt.WindowTitleHint|QtCore.Qt.WindowMaximizeButtonHint)
self.setGeometry(0, 0, 800, 480)
self.setWindowTitle('TEST PROCESSING')
self.quit = QtGui.QPushButton('Close', self)
self.quit.setGeometry(10, 10, 60, 35)
test = QtGui.QPushButton('TEST 2', self)
test.setGeometry(250, 220, 200, 100)
self.connect(self.quit, QtCore.SIGNAL('clicked()'),self.reject)
self.connect(test, QtCore.SIGNAL('clicked()'),self.nextWindow)
def nextWindow(self):
self.Window3.show()
class Window_Test1(QtGui.QDialog):
def __init__(self):
QtGui.QWidget.__init__(self)
self.Window2 = Window_Test2()
self.setGeometry(0, 0, 800, 480)
self.setWindowTitle('TEST PROCESSING' )
test = QtGui.QPushButton('TEST', self)
test.setGeometry(100,100,100,100)
quit = QtGui.QPushButton('Close', self)
quit.setGeometry(10, 10, 60, 35)
self.connect(test, QtCore.SIGNAL('clicked()'),self.nextWindow)
self.connect(quit, QtCore.SIGNAL('clicked()'), self.reject)
def nextWindow(self):
self.Window2.show()
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
Window1 = Window_Test1()
Window1.show()
sys.exit(app.exec_())
Your code recursively initializes new objects.
Window_Test1 calls Window_Test2, which calls Window_Test3, which calls Window_Test1, which calls Window_Test2, which calls Window_Test3, which calls Window_Test1, which... you get the point.
You'll want to either defer the initialization of those objects to when they're actually needed (so not in __init__), or maybe have single instances of all three windows that are referred to.
Create a placeholder self.next_Window for the next window and fill it in after creating all 3 windows
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtGui, QtCore
class Window_Test3(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
global progress_flag
self.next_Window = None
self.setWindowFlags(QtCore.Qt.CustomizeWindowHint|
QtCore.Qt.WindowTitleHint|
QtCore.Qt.WindowMaximizeButtonHint)
self.setGeometry(0, 0, 800,480)
self.setWindowTitle('TEST PROCESSING')
quit = QtGui.QPushButton('Close', self)
quit.setGeometry(10, 10, 60, 35)
test = QtGui.QPushButton('TEST 3', self)
test.setGeometry(100, 200, 200, 100)
self.connect(quit, QtCore.SIGNAL('clicked()'),self.reject)
self.connect(test, QtCore.SIGNAL('clicked()'), self.nextWindow)
def nextWindow(self):
self.next_Window.show()
def setNextWindow(self, nextWindow):
self.next_Window = nextWindow
class Window_Test2(QtGui.QDialog):
def __init__(self):
QtGui.QWidget.__init__(self)
global progress_flag
self.next_Window = None
self.setWindowFlags(QtCore.Qt.CustomizeWindowHint|
QtCore.Qt.WindowTitleHint|
QtCore.Qt.WindowMaximizeButtonHint)
self.setGeometry(0, 0, 800, 480)
self.setWindowTitle('TEST PROCESSING')
self.quit = QtGui.QPushButton('Close', self)
self.quit.setGeometry(10, 10, 60, 35)
test = QtGui.QPushButton('TEST 2', self)
test.setGeometry(250, 220, 200, 100)
self.connect(self.quit, QtCore.SIGNAL('clicked()'),self.reject)
self.connect(test, QtCore.SIGNAL('clicked()'),self.nextWindow)
def nextWindow(self):
self.next_Window.show()
def setNextWindow(self, nextWindow):
self.next_Window = nextWindow
class Window_Test1(QtGui.QDialog):
def __init__(self):
QtGui.QWidget.__init__(self)
self.next_Window = None
self.setGeometry(0, 0, 800, 480)
self.setWindowTitle('TEST PROCESSING' )
test = QtGui.QPushButton('TEST', self)
test.setGeometry(100,100,100,100)
quit = QtGui.QPushButton('Close', self)
quit.setGeometry(10, 10, 60, 35)
self.connect(test, QtCore.SIGNAL('clicked()'),self.nextWindow)
self.connect(quit, QtCore.SIGNAL('clicked()'), self.reject)
def nextWindow(self):
self.next_Window.show()
def setNextWindow(self, nextWindow):
self.next_Window = nextWindow
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
Window1 = Window_Test1()
Window2 = Window_Test2()
Window3 = Window_Test3()
Window1.setNextWindow(Window2)
Window2.setNextWindow(Window3)
Window3.setNextWindow(Window1)
Window1.show()
sys.exit(app.exec_())
There should be only one window instead of three.
def nextWindow (self):
self.next_Window.show()
self.actionEvent (self.reject ()) # Delete current screen
def setNextWindow (self, nextWindow):
self.next_Window = nextWindow
That is, you add self.actionEvent(self.reject ()),
One screen is output.
However, there is a slight jitter when switching the screen.

Call function by Enter key

How can I make (on_click) works when QPushButton ("click") is pressed by Enter keyboard key? it only interacts with mouse_click
import sys
from PyQt5.QtWidgets import *
class Example(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.label = QLabel("",self)
self.label.move(100, 100)
self.button = QPushButton('click', self)
self.button.move(100, 50)
self.button.clicked.connect(self.on_click)
self.setGeometry(500, 150, 200, 200)
self.show()
def on_click(self):
self.label.setText("Hello")
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
You have to overwrite the keyPressEvent method:
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
class Example(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.label = QLabel("",self)
self.label.move(100, 100)
self.button = QPushButton('click', self)
self.button.move(100, 50)
self.button.clicked.connect(self.on_click)
self.setGeometry(500, 150, 200, 200)
self.show()
def on_click(self):
self.label.setText("Hello")
def keyPressEvent(self, event):
if event.key() == Qt.Key_Return:
self.on_click()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
I found a solution regarding this: keyPressEvent() method doesn't work for PyQt5 / Python 3+.
You need to override the function in super class.
MainWindow.keyPressEvent = self.keyPressEvent

PyQt4 - Open *.py file when Button is clicked

I want to open/run a *.py file with pythonw.exe, when the Start-Button is clicked. Can anyone tell me how this works? I havent found the right function anywhere.
import sys
from PyQt4 import QtGui, QtCore
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def initUI(self):
QtGui.QToolTip.setFont(QtGui.QFont('SansSerif', 10))
self.setToolTip('This is a <b>QWidget</b> widget')
btn1 = QtGui.QPushButton('Start', self)
# OPENFILE SOMEHOW!!
btn1.resize(btn1.sizeHint())
btn1.move(20, 20)
qbtn = QtGui.QPushButton('Quit', self)
qbtn.clicked.connect(QtCore.QCoreApplication.instance().quit)
qbtn.resize(qbtn.sizeHint())
qbtn.move(150, 20)
self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('Python Script')
self.show()
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
You can use subprocess.call. For example, this code runs external.py , when the Start is clicked:
import sys
from PyQt4 import QtGui, QtCore
import subprocess
class Example(QtGui.QWidget):
def __init__(self):
super(Example, self).__init__()
self.initUI()
def run(self, path):
subprocess.call(['pythonw',path])
def initUI(self):
QtGui.QToolTip.setFont(QtGui.QFont('SansSerif', 10))
self.setToolTip('This is a <b>QWidget</b> widget')
btn1 = QtGui.QPushButton('Start', self)
btn1.resize(btn1.sizeHint())
btn1.move(20, 20)
btn1.clicked.connect(lambda:self.run('external.py'))
qbtn = QtGui.QPushButton('Quit', self)
qbtn.clicked.connect(QtCore.QCoreApplication.instance().quit)
qbtn.resize(qbtn.sizeHint())
qbtn.move(150, 20)
self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('Python Script')
#subprocess.call(['pythonw','3.py'])
self.show()
def main():
app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
if __name__ == '__main__':
main()

Categories