0
我正在做一個項目,在主類中有一個點,我必須調用帶兩個按鈕的pyqt窗口,這些按鈕被附加到將全局變量的值更改爲「IN 「或」OUT「。但是按下按鈕並改變值後,我無法退出該窗口。首先,讓我告訴你我的GUI類的代碼,看這些代碼的兩個按鈕和IN/OUT功能:pyqt類的退出函數
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()
現在我從同一個文件和另一個類,這是主類的調用它我項目這樣的..
dialog = Window()
dialog.exec_()
img = Image.open(court)
但是IN/OUT窗口不會因此退出 「IMG = Image.open(法院)」 不執行這條線。所以問題是讓按鈕的作用就像它們改變變量一樣,退出窗口並從窗口被調用的地方返回到類。謝謝
確定它沒有關閉窗口,但代碼後 「對話框=窗口() 對話.exec_()' 不工作..它就像它從來沒有返回到關閉gui類窗口後的主類的下一行 –
這是一個不同的問題,然後。你應該搜索* PyQt模態對話框*。因此,您可以閱讀http://stackoverflow.com/q/24697347/3545273或http://stackoverflow.com/q/18196799/3545273,後者解釋瞭如何從子窗口中檢索信息。 –