![](/img/trans.png)
[英]how to run python script from the console as if called from command prompt?
[英]How run a python console script from a hiding console python script?
我在 python 方面不是很有经验,我开始使用 Tkinter 构建应用程序。 就像它是一个 window 项目我用 pythonw.exe 打开它,但它调用控制台脚本,如果第一个脚本被隐藏,我无法显示第二个脚本的控制台......有一段代码调用第二个脚本:
from selenium_script import main
self.btn_downloadAnime = tk.Button(self.frm_addAnime, text='Lunch download script with voiranime.com links',
bg=self.colorBTN, font=22, activebackground=self.colorBG, height=2, width=50,
command=main)
这是你想要的:
main.py
:
import tkinter as tk
import subprocess
import sys
COMMAND = "start python selenium_script.py"
def start_new_proc():
proc = subprocess.Popen(COMMAND, close_fds=False, shell=True)
root = tk.Tk()
button = tk.Button(root, command=start_new_proc, text="Start new process")
button.pack()
root.mainloop()
selenium_script.py
:
user_input = input(">>> ")
print("You typed this: " + str(user_input))
input("Press enter to exit.")
我使用subprocess.Popen
开始一个新进程。 新进程从它自己的 shell 开始(因为COMMAND
变量中的"start"
)
是的,我错过了过程的概念......以前的解决方案有效,我也找到了一个:
def open_selenium(self):
subprocess.Popen(args=['python', 'selenium2.py'], stdout=sys.stdout)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.