【发布时间】:2020-05-07 13:19:58
【问题描述】:
我遇到了一个奇怪的问题。我创建了一个 Python 脚本,它使用自定义股票交易算法向用户提供买卖信号。
我已将 PySide2 用于 GUI 工具包,但我在使用 Tkinter 时也遇到了同样的问题。
首先,这是我的代码的相关sn-ps:
- 主窗口
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
...
...
Create and add GUI widgets
...
...
watch_button = QPushButton("Watch")
watch_button.clicked.connect(self.watch_scrip)
@Slot()
def watch_scrip(self, checked):
ScripWindow(self, ScripInfo(self._scrips_strings[self._scrip_list.currentIndex()])).show()
def closeEvent(self, event):
QApplication.closeAllWindows()
event.accept()
- 为正在观看的单个脚本打开子窗口
class ScripWindow(QMainWindow):
def __init__(self, parent, scrip_info):
QMainWindow.__init__(self, parent)
...
...
Create and add GUI widgets
...
...
self._scrip_queue = Queue()
self._scrip_algo = ScripAlgo(self._scrip_queue)
self._scrip_algo_process = Process(target=self._scrip_algo.run_algo)
self._scrip_algo_process.start() <-- Start algorithm in a new background process which writes to Queue
QTimer.singleShot(1000, self._process_queue)
def _process_queue(self):
while not self._scrip_queue.empty():
data_string = self._scrip_queue.get()
...
...
Read and display data from the Queue object generated by algorithm
...
...
QTimer.singleShot(1000, self._process_queue)
def closeEvent(self, event):
self._scrip_algo_process.terminate()
event.accept()
脚本通过 Python 完美运行。即使是“pythonw my_app.pyw”也可以在没有控制台的情况下运行。
当我使用 Pyinstaller 创建 .exe 文件时出现问题。当我运行 .exe 文件时,它会打开 MainWindow。当我按下“Watch”按钮时,它会打开一个子窗口(ScripWindow),就像它应该的那样。但它也会打开另一个主窗口。
可能是什么问题?又该如何解决呢?
提前致谢。
【问题讨论】:
标签: python pyinstaller pyside2