I am using IDLE (Python 3.6 64-bit). Currently, I am using Tkinter to create a GUI. I have a button in my code that is supposed to terminate the program. As of now, it only closes out the "tk" root window (using root.destroy()). I want it to also close out the shell and go back to where I can edit the code (i.e. back to my IDLE). How can I do this?
When you run code from an IDLE editor window, any existing program run from IDLE is terminated. Unless your code somehow grabs control of the mouse, you should always be able to click on any editor window or its taskbar icon (on Windows) and start editing some more. Example: run the following from an IDLE editor.
import tkinter as tk
root = tk.Tk()
#root.destroy()
A tk window is dispayed. Click on the editor window, remove the '#', and run again. The first tk window disappears and a >>> prompt appears in the Shell window.
A python program run from IDLE, cannot* close its parent IDLE, anymore than a python program run in a console can close the parent console.
I am excluding things like, on *nix, getting the parent process number and issuing a 'kill ' command.
Related
If have a tkinter gui for managing pypresence commands.
Github
Problem
When I press the close button of the window the window closes, but the console stays open.
I tried other stuff, with py2exe but then sometimes the task stays, and you have do kill it manually.
But not to forget, i want that the console is there, but it should exit when i press exit in the tkinter window
I found this answers on Stackoverflow but nothing works for me
How to hide console window in python?
Hiding the console window
Hide console window with Tkinter and cx_Freeze
I'm trying to hide console window, on windows at least. But with solutions above still I have window open
The only difference maybe I have to mark, I run python application with process from C# application, but as I understand it can't be a reason of some key different if I write all directives from the python code. Now I'm not sure how to figure out
You need to use the pythonw.exe program as it won't open a terminal when ran.
I've used Tkinter or wxWidgets for some projects: this opens a new window in graphical mode (GUI) in which you can do what you want.
Can I ask Python to open a new text-mode window (let's say 80x25 terminal), independant from the terminal where I run myscript.py,
in the same way that a Tkinter window is independant from the current terminal where I run myscript.py?
What do I want to achieve? Having a GUI, but in textmode! (this might sound tricky because G in GUI means graphical!)
Does tkInter, wxWidget, pyglet, etc. have a feature to open a text-mode terminal-look GUI? With 80x25 text display?
For this you will need to make a seperate script but it works.
Use this code in your launcher script.
from sys import executable
from subprocess import Popen, CREATE_NEW_CONSOLE
Popen([executable, 'myscript.py'], creationflags=CREATE_NEW_CONSOLE)
input('Enter to exit from this launcher script...')
Source
I'm using the subprocess library to call a program which would open a new window. The only problem is that this window opens below my terminal, which is a bit of a nuisance.
Is there any way to have the window open above my current window?
I am a complete newbie at Python. Meanwhile, I'm working with Tkinter to integrate a GUI into my application using Python 2.7. This is the code so far:
import Tkinter
top = Tkinter.Tk()
top.mainloop()
However, when I execute the file, a console window and the GUI pops up. How do I get rid of the console window during startup?
Rename your Python script as .pyw (not .pyc). This will tell the invoker to to instantiate a console window. Source
Note however, this will work for non-GUI based scripts too which can cause undesireqable behaviour - such as not being able to see your script.