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
Related
I wrote a program to start and stop an AutoHotKey script in the tkinter GUI for my non-coding coworkers to use but the autohotkey script has to be able to send commands through the python shell and I just realized that while the tkinter window is open, I am unable to send commands through the shell. I know theres an AutoHotKey library for Python but I really don't want to have to rewrite too much if possible. Is there anyway to keep the tkinter window up and running while also calling other functions from the shell?
I don't know what to try other than rewriting the whole thing using the AHK library.
I have a CLI application with no GUI. This application uses CMD to launch and display some information (long-running process -- localhost-server). I want to add a feature where we can hide the window when we don't want to see it and unhide the window when we want to see it.
I tried to achieve that using Python Module Pystray but it only hides GUI applications in the system tray. It does not hide CMD in the system tray.
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.
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.
problem
I started designing GUI applications using Python and Tkinter. When I freeze a script using cxFreeze then when I run that EXE file on a machine. Then first the console window (a black DOS shell in the case of Windows XP) opens and then the main window(Tk() instance) gets initialized.
goal
The console window must not appear. Only the Tk() instance should appear.
code
root = Tk()
Label(root,text="hey").pack()
root.mainloop()
specs
Windows XP SP 3
Python 2.7
Tkinter 8.5
When using py2exe use windows=['main.py'] instead of console=['main.py'] when creating your setup.py
For cx_Freeze this answer might help you: https://stackoverflow.com/a/11374527/2256700
I'm not sure if this is the answer anyone is looking for, but renaming the file extension from .py to .pyw under Python 3.4 and Win32 will effectively suppress the Python shell. You'll just get your Tk GUI window.
Say your python script is called "myscript.py".
Create a file called runme.vbs containing code:
Set WshShell = CreateObject("WScript.Shell")
cmds=WshShell.RUN("myscript.py", 0, True)
Set WshShell = Nothing