def start(): global img, pre_pts while True: root = tk.Tk() root.withdraw() f_path = filedialog.askopenfilename() if f_path: img = cv.imread(f_path) break else: messagebox.showinfo("提示", "请选择文件!") 修改上述代码,使得打开本地文件夹不选文件或者关闭系统窗口后,使得下面的主界面窗口按钮仍能够触发start()函数class Faceshow(QMainWindow, Ui_MainWindow): def init(self, parent=None): super(Faceshow, self).init(parent) self.setupUi(self) self.main_button.clicked.connect(self.show_resu) self.main_exit.clicked.connect(self.quit) self.form = None def show_resu(self): img1, img2, img3, img4, text1, text2 = start() img1 = ndarray_to_qpixmap(img1) img2 = ndarray_to_qpixmap(img2) img3 = ndarray_to_qpixmap(img3) img4 = ndarray_to_qpixmap(img4) self.form = RESUshow(img1, img2, img3, img4, text1, text2) self.form.pushButton.clicked.connect(self.form.save_img4) self.form.show() 另外start()和Faceshow窗口不在同一个py文件
时间: 2023-06-26 09:05:08 浏览: 145
JavaScriptS1.rar_.CHM_JavaScriptS1_chm_java chm_pts
修改后的代码如下:
```python
def start():
global img, pre_pts
root = tk.Tk()
root.withdraw()
f_path = filedialog.askopenfilename()
if f_path:
img = cv.imread(f_path)
root.destroy() # 关闭系统窗口
return process_img(img)
else:
messagebox.showinfo("提示", "请选择文件!")
root.destroy() # 关闭系统窗口
return None, None, None, None, None, None
class Faceshow(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(Faceshow, self).__init__(parent)
self.setupUi(self)
self.main_button.clicked.connect(self.show_resu)
self.main_exit.clicked.connect(self.quit)
self.form = None
def show_resu(self):
resu = start()
if resu:
img1, img2, img3, img4, text1, text2 = resu
img1 = ndarray_to_qpixmap(img1)
img2 = ndarray_to_qpixmap(img2)
img3 = ndarray_to_qpixmap(img3)
img4 = ndarray_to_qpixmap(img4)
self.form = RESUshow(img1, img2, img3, img4, text1, text2)
self.form.pushButton.clicked.connect(self.form.save_img4)
self.form.show()
```
另外,需要将 `start()` 函数所在的文件导入到 `Faceshow` 所在的文件中,可以使用类似 `from 文件名 import start` 的语句。
阅读全文