How do i open a class from within another class by selecting an item on ToolBar?? Python/PyQt

user3501179

I am trying to run class AddTQuestions from a def in class AddTest but it wont work!! It opens the window AddTQuestions for a split-second then closes it straight away?!

The code is shown here:

import sys
from PyQt4 import QtCore, QtGui

class Example(QtGui.QMainWindow):
    def __init__(self):
        super(Example, self).__init__()
        self.initUI()
    def initUI(self):               
        RunClassAction = QtGui.QAction(QtGui.QIcon('exit24.png'), 'Exit', self)
        RunClassAction.triggered.connect(self.run)
        self.toolbar = self.addToolBar('Exit')
        self.toolbar.addAction(RunClassAction)
        self.setGeometry(300, 300, 300, 200)
        self.setWindowTitle('Why Wont this Woooorkkkkk')    
        self.show()

    def run(self):
        AddQuestion = AddTQuestions()
        AddQuestion.show()

class AddTQuestions(QtGui.QMainWindow):
    def __init__(self, parent=None):
        super(AddTQuestions, self).__init__(parent)
        self.welldone = QtGui.QLabel('WellDone')
        self.button = QtGui.QPushButton('Press Me')
        layout = QtGui.QVBoxLayout()
        layout.addWidget(self.welldone)
        layout.addWidget(self.button)
        self.setLayout(layout)
        print("hello")


if __name__ == '__main__':
    app = QtGui.QApplication([])
    window = Example()
    window.show()
    app.exec_()
M4rtini

The object get's garbage collected, since you don't hold any reference to it when the function ends.

add them as class variables like this and the window stays open.

self.AddQuestion = AddTQuestions()
self.AddQuestion.show()

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

How do I use a HashMap from another class or function?

분류에서Dev

How do I reference a string in another class?

분류에서Dev

How do I return the result of a class-based view from another class-based view in Django?

분류에서Dev

How do I set the value of my field so that I can call it from another class?

분류에서Dev

How do i set the text of a TextView to a value of an integer from another class

분류에서Dev

How can I access a class data member from a method within the same class?

분류에서Dev

How can I do an array of object of my class (with inheritance of another custom class)?

분류에서Dev

How to access variable from another class directly(i.e. without using class name or object)?

분류에서Dev

How do I return a first class module from the same module?

분류에서Dev

How do I override the default way Wordpress' determines the .current-menu-item class?

분류에서Dev

How do i dynamically cast a child class from its parent class?

분류에서Dev

How do I pass data from a widget config class to a widget provider class via intents?

분류에서Dev

How to access an ArrayList from another class

분류에서Dev

How to call a function from another class in python

분류에서Dev

How do I pass a single Firestore document ID to another class based on a selection using Flutter/Dart?

분류에서Dev

How do I center an element within a div with another element nearby?

분류에서Dev

How do I use the GeometryConstraint class?

분류에서Dev

How can I add a class to the "action" item in Ember?

분류에서Dev

How to add a class within php

분류에서Dev

create an instance of one class from another class

분류에서Dev

How Do I Solve Alert Dialog leaks from a class that is passed a context?

분류에서Dev

How do I Use other functions from a different class in Asynchronous methods

분류에서Dev

How can I pass the stringbuilder and display out in another class

분류에서Dev

Running code from another class

분류에서Dev

Android onClick from another class

분류에서Dev

how to call class AsyncTask to another class?

분류에서Dev

How to change the class of an element based on the class of another

분류에서Dev

How to keep track of instances of another class in a class?

분류에서Dev

How to set text for JTextField from another class using DocumentFIlter?

Related 관련 기사

  1. 1

    How do I use a HashMap from another class or function?

  2. 2

    How do I reference a string in another class?

  3. 3

    How do I return the result of a class-based view from another class-based view in Django?

  4. 4

    How do I set the value of my field so that I can call it from another class?

  5. 5

    How do i set the text of a TextView to a value of an integer from another class

  6. 6

    How can I access a class data member from a method within the same class?

  7. 7

    How can I do an array of object of my class (with inheritance of another custom class)?

  8. 8

    How to access variable from another class directly(i.e. without using class name or object)?

  9. 9

    How do I return a first class module from the same module?

  10. 10

    How do I override the default way Wordpress' determines the .current-menu-item class?

  11. 11

    How do i dynamically cast a child class from its parent class?

  12. 12

    How do I pass data from a widget config class to a widget provider class via intents?

  13. 13

    How to access an ArrayList from another class

  14. 14

    How to call a function from another class in python

  15. 15

    How do I pass a single Firestore document ID to another class based on a selection using Flutter/Dart?

  16. 16

    How do I center an element within a div with another element nearby?

  17. 17

    How do I use the GeometryConstraint class?

  18. 18

    How can I add a class to the "action" item in Ember?

  19. 19

    How to add a class within php

  20. 20

    create an instance of one class from another class

  21. 21

    How Do I Solve Alert Dialog leaks from a class that is passed a context?

  22. 22

    How do I Use other functions from a different class in Asynchronous methods

  23. 23

    How can I pass the stringbuilder and display out in another class

  24. 24

    Running code from another class

  25. 25

    Android onClick from another class

  26. 26

    how to call class AsyncTask to another class?

  27. 27

    How to change the class of an element based on the class of another

  28. 28

    How to keep track of instances of another class in a class?

  29. 29

    How to set text for JTextField from another class using DocumentFIlter?

뜨겁다태그

보관