Python 3.6.2 and Windows 10 environments.
from tkinter import*
import subprocess
def func1():
print ("click")
def func2():
subprocess.run(("start", "timeout", "/T", "10", shell=True)
root=Tk()
Button(root, text="Button1", command=func1).pack()
Button(root, text="Button2", command=func2).pack()
mainloop()
When booting, hide the console with the extension pyw.
How do I get a command prompt to print when I click button 1 (func1 is an example, so it can disappear immediately)?
I'd like to use subprocess like button 2.
Thank you for your cooperation.
Instructions for changing the standard output to verify the print content are found in Home SO.
This answer is not a way to view the console.
Please note that this is the only way to display output outside of the console.
from tkinter import*
import subprocess
import sys
def func1():
print ("click")
def func2():
subprocess.run(("start", "timeout", "/T", "10", shell=True)
# Additional mode ("a" → "w" if you want to view only the latest logs)
sys.stdout=open("mylog.txt", "a")
root=Tk()
Button(root, text="Button1", command=func1).pack()
Button(root, text="Button2", command=func2).pack()
mainloop()
© 2024 OneMinuteCode. All rights reserved.