我搜索和搜索了网页,尝试了几乎所有的代码,但仍然无法将cmd.exe隐藏在后台(只有在命令从计算机上打开一个exe (例如打开word.exe)时才会发生),其他按钮不会打开cmd.exe,因为是打开来自web的链接。我很抱歉,我是python的初学者,我刚刚让老师给了我们基础知识,但是我爱上了python,所以我决定在家学习,并尝试使用我的应用程序。非常感谢您的答复。和平
注意:我有两个文件。一条已经转换成exe的python,一条在python中,我尝试pyw,pyc,打开一个python窗口,在另一个窗口中,您可能想到的所有东西我都做了。现在,我正在处理python (boss.pyw)的原始文件,我将在下面显示完整的代码,并将命令放在哪里,这样cmd.exe就不会出现。
导入功能工具导入sys导入ctype导入urllib.request导入os导入sys浏览器从tkinter导入*导入idlelib从tkinter导入messagebox导入tkinter作为tk导入子进程
def programs():
class LoginFrame(Frame):
def __init__(self, master):
super().__init__(master)
self.logbtn0 = Button(self, text="SKIDROW", command=self._login_btn_clicked0, fg='#ff00bf', height = 4, width = 12)
self.logbtn0.grid(columnspan=4)
self.logbtn6 = Button(self, text="""Planet
Romeo""", command=self._login_btn_clicked6, fg='#990000', height = 4, width = 12)
self.logbtn6.grid(columnspan=4)
self.logbtn7 = Button(self, text="""Sair
Programa""", command=self._login_btn_clicked7, fg='#b366ff', height = 4, width = 12)
self.logbtn7.grid(columnspan=4)
self.logbtn = Button(self, text="EXCEL", command=self._login_btn_clicked, fg='#00b33c', height = 4, width = 12)
self.logbtn.grid(columnspan=2)
self.logbtn1 = Button(self, text="WORD", command=self._login_btn_clicked1, fg='#ff4000', height = 4, width = 12)
self.logbtn1.grid(columnspan=2)
self.logbtn5 = Button(self, text="FILMORA", command=self._login_btn_clicked5, fg='#ff00bf', height = 4, width = 12)
self.logbtn5.grid(columnspan=1)
self.logbtn2 = Button(self, text="NOTEPAD", command=self._login_btn_clicked2, fg='#0000ff', height = 4, width = 12)
self.logbtn2.grid(columnspan=1)
self.logbtn3 = Button(self, text="""POWER POINT
""", command=self._login_btn_clicked3, fg='#8000ff', height = 4, width = 12)
self.logbtn3.grid(columnspan=1)
self.logbtn4 = Button(self, text="FACEBOOK", command=self._login_btn_clicked4, fg='#0059b3', height = 4, width = 12)
self.logbtn4.grid(columnspan=2)
self.logbtn0.grid(row=1, sticky=N)
self.logbtn.grid(row=1, sticky=N)
self.logbtn1.grid(row=2, sticky=N)
self.logbtn2.grid(row=1, sticky=N)
self.logbtn3.grid(row=2, sticky=N)
self.logbtn4.grid(row=3, sticky=N)
self.logbtn5.grid(row=3, sticky=N)
self.logbtn6.grid(row=2, sticky=N)
self.logbtn7.grid(row=3, sticky=N)
self.logbtn0.grid(row=1, column=4)
self.logbtn.grid(row=1, column=2)
self.logbtn1.grid(row=2, column=2)
self.logbtn2.grid(row=1, column=1)
self.logbtn3.grid(row=2, column=1)
self.logbtn4.grid(row=3, column=2)
self.logbtn5.grid(row=3, column=1)
self.logbtn6.grid(row=2, column=4)
self.logbtn7.grid(row=3, column=4)
self.pack()
def _login_btn_clicked(self):
dialog_title = "Responda por favor"
dialog_text = "DESEJA ABRIR O EXCEL?"
answer = messagebox.askquestion(dialog_title, dialog_text,)
if answer == "yes":
path = "C:/Program Files (x86)/Microsoft Office/root/Office16/"
os.chdir(path)
os.system("EXCEL.exe")
else:
return
def _login_btn_clicked1(self):
dialog_title = "Responda por favor"
dialog_text = "DESEJA ABRIR O WORD?"
answer = messagebox.askquestion(dialog_title, dialog_text,)
if answer == "yes":
path = "C:/Program Files (x86)/Microsoft Office/root/Office16/"
os.chdir(path)
os.system("WINWORD.exe")
else:
return
def _login_btn_clicked2(self):
dialog_title = "Responda por favor"
dialog_text = "DESEJA ABRIR O NOTEPAD?"
answer = messagebox.askquestion(dialog_title, dialog_text,)
if answer == "yes":
path = "C:/Program Files (x86)/Notepad++"
os.chdir(path)
os.system("notepad++.exe")
else:
return
def _login_btn_clicked3(self):
dialog_title = "Responda por favor"
dialog_text = """DESEJA ABRIR O POWER
POINT?"""
answer = messagebox.askquestion(dialog_title, dialog_text,)
if answer == "yes":
path = "C:/Program Files (x86)/Microsoft Office/root/Office16"
os.chdir(path)
os.system("POWERPNT.exe")
else:
return
def _login_btn_clicked4(self):
dialog_title = "Responda por favor"
dialog_text = "DESEJA IR PARA ESTE SITE?"
answer = messagebox.askquestion(dialog_title, dialog_text,)
if answer == "yes":
webbrowser.open('https://www.facebook.com/francisco.neves.16718979')
else:
return
def _login_btn_clicked0(self):
dialog_title = "Responda por favor"
dialog_text = "DESEJA IR PARA ESTE SITE?"
answer = messagebox.askquestion(dialog_title, dialog_text,)
if answer == "yes":
webbrowser.open('https://www.skidrowreloaded.com/')
else:
return
def _login_btn_clicked5(self):
dialog_title = "Responda por favor"
dialog_text = "DESEJA ABRIR O FILMORA?"
answer = messagebox.askquestion(dialog_title, dialog_text,)
if answer == "yes":
path = "C:/Program Files/Wondershare/Filmora"
os.chdir(path)
os.system("Filmora.exe")
else:
return
def _login_btn_clicked6(self):
dialog_title = "Responda por favor"
dialog_text = "DESEJA IR PARA ESTE SITE?"
answer = messagebox.askquestion(dialog_title, dialog_text,)
if answer == "yes":
webbrowser.open('https://www.planetromeo.com/radar/home')
else:
return
def _login_btn_clicked7(self):
quit()
root = tk.Tk()
lf = LoginFrame(root)
root.mainloop()
def main():
programs()
if __name__ == ("__main__"):
main()发布于 2019-04-06 11:33:07
停止使用os.system;os.system在shell中运行有问题的程序,在Windows上运行,这意味着cmd.exe。使用subprocess模块来启动没有外壳包装的程序,它应该工作得很好。例如:
os.system("POWERPNT.exe")只需替换它,subprocess.run
subprocess.run(["POWERPNT.exe"])或者让它在后台运行, instead。您也可能希望查看 on Windows的特定行为,但首先尝试普通运行。
发布于 2019-04-06 09:34:18
在将.py转换为.exe时,添加此标志
---windowedhttps://stackoverflow.com/questions/55547109
复制相似问题