Home > Back-end >  Is it possible to prevent terminal from hanging after running a tkinter program
Is it possible to prevent terminal from hanging after running a tkinter program

Time:05-03

I have written a tkinter program but anytime I run the program, the terminal hangs. Is there any way in python to add to the program that will prevent terminal from hanging whilst the tkinter program is still running like in the last part? Any suggestions are welcomed. Thanks in advance

### Terminal hangs without showing the working directory ####

PS C:\Users\DANIEL\Desktop\exp\fcnvmb\results> python3 c:/Users/DANIEL/Desktop/exp/fcnvmb/GUI.py

*******************************************
            START TESTING
*******************************************
C:\ProgramData\Anaconda3\lib\site-packages\torch\nn\_reduction.py:42: UserWarning: size_average and reduce args will be deprecated, please use reduction='mean' instead.
  warnings.warn(warning.format(ret))
The testing psnr: 15.81, SSIM: 0.5168 
Testing complete in  0m 2s



#### I want the working directory to show in the terminal whilst the tkinter program is still running like below ####

PS C:\Users\DANIEL\Desktop\exp\fcnvmb\results> python3 c:/Users/DANIEL/Desktop/exp/fcnvmb/GUI.py

*******************************************
            START TESTING
*******************************************
C:\ProgramData\Anaconda3\lib\site-packages\torch\nn\_reduction.py:42: UserWarning: size_average and reduce args will be deprecated, please use reduction='mean' instead.
  warnings.warn(warning.format(ret))
The testing psnr: 15.81, SSIM: 0.5168 
Testing complete in  0m 2s
PS C:\Users\DANIEL\Desktop\exp\fcnvmb\results>

CodePudding user response:

Yes, use the pythonw command instead of python3. It is an identical interpreter, but it is configured as a GUI app instead of a Win32 console app, so that it does not stayed attached to the console.

That, of course, means that you can't write to stdout any more. There won't BE a stdout. That's the tradeoff.

  • Related