pyttsx3 is conflicting with tkinter - python-3.x

My tkinter app will run console-free (.pyw) until I import pyttsx3. As soon as pyttsx3 is imported, the app will only run from the editor (Idle).
This is a tkinter app that runs perfectly when run from idle. I import pyttsx3, initialize it, have it speak using Windows Sapi voices, all is well, all tkinter functions operate as intended from start to finish. But outside of Idle, the app won't run in .pyw mode. It shows a black console screen for a brief moment and closes. I have checked very carefully - removing all pyttsx3 code from the app - except the import statement and, quite literally, the import statement alone is enough to cause the app to no longer run in .pyw mode.
import tkinter as tk
(runs fine in .pyw mode)
import tkinter as tk
import pyttsx3 as speak
(will not run in .pyw mode)
The question: how could simply importing a library (not even initializing or using it...just importing it) cause the tkinter app to no longer run as .pyw? Could importing a library somehow be interfering with the tkinter main loop?

Good question. If I had to guess, something in the pyttsx3 library invokes a process that is unrelated to Python, for the purpose of text-to-speech conversion. Windows probably opens a Command Prompt window in such a case since that process runs independently.
Unless the pyttsx3 library has documentation for how to suppress this—after a cursory glance, I don't see such—then I would recommend opening a new issue with the package maintainer. I believe that it would need to set the CREATE_NO_WINDOW flag when being run on Windows.

Related

subprocess works but unexpected black screen

I'm trying to open the DellCommandUpdate with python in full screen. I can get the application to open with the first code but couldn't figure out how to maximize the screen. Someone suggested trying sub process. It comes up as a black window similar to cmd.
import os
os.startfile("C:\Program Files (x86)\Dell\CommandUpdate\DellCommandUpdate.exe")
import subprocess
subprocess.call(["cmd", "/c", "start", "/max", "C:\Program Files (x86)\Dell\CommandUpdate\DellCommandUpdate.exe"])
The goal for this is to be able to open the program to be able to click update. I'm not sure if there is something like selenium but for desktop apps or how I would program to automate this

disable failSafeCheck Python PyAutoGui without editing the pyautogui file

So I'm using PyCharm as a python editor, and I don't know if it's because of my editor, but whenever I run a simple PyAutoGui program such as:
import time, pyautogui
time.sleep(3)
while True:
pyautogui.hotkey('ctrl', 'r')
time.sleep(15)
for too long, I keep getting an error (I don't have that error currently, because I usually have to wait a long time before getting the error from pyautogui. But it looks something like) :
PyAutoGUI fail-safe triggered from mouse moving to a corner of the screen.
I'm not very experienced with Python PyAutoGui module, but is there a way to disable that safe-check without doing something in the pyautogui python file?
You're in luck! Just add pyautogui.FAILSAFE = True right after importing the library.
Check out their docs it has a lot of good info.

ipython problem: Tkinter GUI does not open

I tried to implement the following code, which should be used to get the file path of a file, using tkinter's gui:
from tkinter import filedialog
from tkinter import *
root = Tk()
root.filename = filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("jpeg files","*.jpg"),("all files","*.*")))
print (root.filename)
... the program runs, there are no errors, but also there is no tkinter window to chose a file.
I got the code from: https://pythonspot.com/tk-file-dialogs/
My operating system: Windows 10
I am using Spider from Anaconda to run the code.
EDIT:
If I change the system setting to execute in an external system terminal it works:
Why does it not work in an IPython 6.4.0 terminal?
EDIT 2:
Also changing the settings to execute in dedicated console works:
Tkinter runs in a single thread, and the .mainloop() method starts up the thread, which is actually an infinite loop till the user/another event closes the window.
This means that if you create all the widgets that should run in your window and you do not invoke .mainloop(), your code will run but the window will not come up as there is no mainloop() to begin the root Tk loop.

Clear screen with CMD disabled

I'm trying to clear the screen in my Idle text editor (the default one that comes with python (and is basically command prompt anyway).
I have had this problem for a while now and i've searched just about every corner of the web but nothing has truly answered my problem.
import subprocess
import subprocess as sp
import os
os.system('cls')
does not work
Ctrl + L does not work
clearing modules also do not work
Using this for loading screens, animations etc... would be a dream com true so if anyone can find a way to do this it would be much appreciated.

python-3.x,ipython3,pyqt5 How to link ipython3 to pyqt5 on startup?

I just noticed, when I was importing a file from my project I'm working on, that ipython3 is a little bit confused, because the file imports pyqt5 stuff.
Installed are both pyqt4 and 5, because have to use older versions from colleagues, who didn't upgrade their stuff yet.
My projects use pyqt5 so, how do I link ipython3 qtconsole --pylab=qt& to pyqt5 on default?
The error message was:
2
3 import sys, os, math, shutil, re
----> 4 from PyQt5 import QtCore, QtGui, QtWidgets
5 from ui_IMEX import Ui_IMEX
6
RuntimeError: the PyQt5.QtCore and PyQt4.QtCore modules both wrap the QObject class
which I interpret as pyqt4 is connected on default... because it's there.
Cheers,
Christian
Till yesterday I tried to figure out how to get ipython (versions 2.3.1 and 3.xdev) to accept --pylab=qt5 (or similar: qt5agg, qt5Agg) but no luck. If one takes a look at the documentation the kernel directives mention them but the code doesn't. I noticed that some parts aren't even python3 ready and having issues with hte print() statements by lacking the brackets.
For support, I'm adviced to look here but it seams that it isn't any issue here and the once who tried to help aren't working with that versions or didn't get that deep into ipython to come across.
It is damm onerous having to start and stop the program I'm working on just to see that it's not doing what I want. Debugging that way is most unpleasant and that's why iypthon is in so much use for developing.
So, aren't there any more ideas how to fix that?

Resources