I'm having a strange problem. I have created a Python script which uses a custom stock trading algorithm to give buy and sell signals to the user.
I have used PySide2 for the GUI toolkit, but I'm getting the same issue with Tkinter as well.
First, here are the relevant snippets of my code:
- Main Window
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()
- Child windows opening for individual scrips being watched
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()
The script runs perfectly via Python. Even "pythonw my_app.pyw" runs without console just fine.
The problem arises when I use Pyinstaller to create a .exe file. When I run the .exe file, it opens up the MainWindow. When I press the 'Watch' button, it opens a child window (ScripWindow) like it is supposed to. But it also opens up another Main window.
What could be the problem? And how to solve it?
Thanks in advance.