I am doing a project in which there is a point in main class where i have to call a pyqt window with two buttons, those buttons are attached to functions which change value of global variable to "IN" or "OUT". But i am unable to exit that window after button is pressed and value is changed. Let me first show you my gui class code, look out the code for the two buttons and IN/OUT functions:
class Window(QtGui.QMainWindow):
def __init__(self):
self.window_exec = None
self.window_about = None
self.window_help = None
super(Window, self).__init__()
self.setGeometry(0, 0, 500, 400)
self.setWindowTitle('Court Selection')
self.setStyleSheet("background-color:#003333")
#palette = QtGui.QPalette()
#palette.setBrush(QtGui.QPalette.Background,QtGui.QBrush(QtGui.QPixmap("pic1.jpg")))
#self.setPalette(palette)
self.center()
self.default_layout()
self.show()
# Positioning window in the center
def center(self):
frameGm = self.frameGeometry()
screen = QtGui.QApplication.desktop().screenNumber(QtGui.QApplication.desktop().cursor().pos())
centerPoint = QtGui.QApplication.desktop().screenGeometry(screen).center()
frameGm.moveCenter(centerPoint)
self.move(frameGm.topLeft())
def default_layout(self):
# ----------- Main label -----------
lbl = QtGui.QLabel("Please Select the Verdict", self)
lbl.move(100, 70)
lbl.setStyleSheet('font-size:20pt;color:white')
lbl.resize(lbl.sizeHint())
# ----------- IN Button -----------
btn = QtGui.QPushButton("IN", self)
btn.clicked.connect(self.IN)
btn.setStyleSheet('font-size:12pt;background-color:white;border-radius:5px;')
btn.resize(QtCore.QSize(100, 50))
btn.move(200, 170)
# ----------- OUT Button -----------
btn = QtGui.QPushButton("OUT", self)
btn.clicked.connect(self.OUT)
btn.setStyleSheet('font-size:12pt;background-color:white;border-radius:5px;')
btn.resize(QtCore.QSize(100, 50))
btn.move(200, 250)
def IN(self):
global verdict
verdict='IN'
self.exit()
def OUT(self):
global verdict
verdict='OUT'
self.exit()
now i am calling it from the same file and another class, which is main class of my project like this..
dialog = Window()
dialog.exec_()
img = Image.open(court)
But the IN/OUT window doesn't exit hence "img = Image.open(court)" this line is not executed. So the issue is to make buttons act like that they change the variable, exit the window and return to the class from where window was called. Thanks