This forum has been archived. All content is frozen. Please use KDE Discuss instead.

QPushButton Event in Python

Tags: None
(comma "," separated)
User avatar
masooddwi
Registered Member
Posts
2
Karma
0
OS

QPushButton Event in Python

Wed Nov 27, 2013 7:40 pm
Hi

Please see the following code.
-----------------------------------------------------------------
Code: Select all

    from PySide.QtGui import *
    from PySide.QtCore import *
    import sys
    import os
   
    class my_continer(QWidget):
        def __init__(self,tol,ars):
            QWidget.__init__(self)
            self.setFixedSize(tol,ars)
            self.button=QPushButton(u"Exit From Application",self)
            self.connect(self.button,SIGNAL("clicked()"),self.aaa())
        def aaa(self):exit(0)
   
    if __name__=="__main__":
        a=QApplication(sys.argv)
        continer=my_continer(500,350)
        continer.show()
        r=a.exec_()
   

-----------------------------------------------------------------

i want to When I click on a button, the program will exit.
But when I run the program, the clicked event of button is executed automatically and it is Exit Program. and No error does show

Please help me
Thank you
User avatar
scummos
Global Moderator
Posts
1175
Karma
7
OS

Re: QPushButton Event in Python  Topic is solved

Wed Nov 27, 2013 9:34 pm
Don't use the C++ connect syntax -- it sucks for python. Instead, use:

self.button.clicked.connect(self.aaa)

Besides, the actual problem in your code is that you try to connect to self.aaa() which calls the function. You should connect to the function object itself, which is self.aaa.

Greetings


I'm working on the KDevelop IDE.
User avatar
masooddwi
Registered Member
Posts
2
Karma
0
OS

Re: QPushButton Event in Python

Thu Nov 28, 2013 8:57 pm
Hi scummos
You true said and true worked
Thank you very much
Good luck


Bookmarks



Who is online

Registered users: Bing [Bot], Google [Bot], Sogou [Bot]