我想保存/存儲在app.exec()運行時創建的鼠標事件值。我想用下面的代碼,我從我有麻煩現在發現後得到了。(會不會帶鏈接更新發布,其中該代碼,一旦我找到它來了。)如何保存app.exec()在python中退出後使用的值?
import sys
from PyQt4 import QtGui, QtCore
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import numpy as np
class DrawImage(QMainWindow):
def __init__(self,fName, parent=None):
## Default values
self.x = 0
self.y = 0
super(QMainWindow, self).__init__(parent)
self.setWindowTitle('Select Window')
self.local_image = QImage(fName)
self.local_grview = QGraphicsView()
self.setCentralWidget(self.local_grview)
self.local_scene = QGraphicsScene()
self.image_format = self.local_image.format()
#self.pixMapItem = self.local_scene.addPixmap(QPixmap(self.local_image))
self.pixMapItem = QGraphicsPixmapItem(QPixmap(self.local_image), None, self.local_scene)
self.local_grview.setScene(self.local_scene)
self.pixMapItem.mousePressEvent = self.pixelSelect
def pixelSelect(self, event):
# print(event.pos().x(), event.pos().y())
self.x = event.pos().x()
self.y = event.pos().y()
print(self.x, self.y)
def main():
# Initialize
fName = "N2-600-PSI-V1-40-30ms-1.tiff"
app = QtGui.QApplication(sys.argv)
form = DrawImage(fName)
form.show()
app.exec_()
x,y = app.exec_()
print(x,y)
return
if __name__ == '__main__':
main()
我的第一個嘗試創建兩個全局變量,然後使用pixelSelect函數來保存event.pos()。x()和。()y的值。然而
這個工作......最終我想傳遞的不僅僅是一個座標集多出了app.exec()循環的......(工藝??它是一個奇怪的野獸)
所以從這一點我已經嘗試了幾種不同的方法將數組傳遞到app.exec()以保存更多的值。到目前爲止,我得到的最好結果是使用全局數組,並嘗試在DrawImage類中進行for循環。
任何指針將是偉大的:)
有一個很好的!
非常感謝。我還沒有時間,但顯然這是我缺乏面向對象的知識。這個週末我必須花時間來刷新我的OOP。非常感謝。 –