如何解决PyInstaller --noconsole运行应用程序后仍显示控制台
我已经构建了一个应用程序,每次有人从PC插入或拔出USB驱动器时都可以下载和播放声音。 代码:
from playsound import playsound
from win10toast import ToastNotifier
from time import sleep
from typing import Callable
import threading
import os
import youtube_dl
import win32file
def play_audio():
try:
path = os.getcwd() + "\\audio.mp3"
ydl_opts = {
'format': 'bestaudio/best','postprocessors': [{
'key': 'FFmpegExtractAudio','preferredcodec': 'mp3','preferredquality': '192',}],'outtmpl': path
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download(['https://www.youtube.com/watch?v=_0HTwQjMr9k'])
playsound(path)
except Exception as e:
toast = ToastNotifier()
toast.show_toast("RIP prank failed byq","no ogolnie prank failed rip co jest?",duration=20)
def get_drives():
drive_list = []
drivebits = win32file.GetLogicalDrives()
for d in range(1,26):
mask = 1 << d
if drivebits & mask:
drname = '%c:\\' % chr(ord('A') + d)
t = win32file.GetDriveType(drname)
if t == win32file.DRIVE_REMOVABLE:
drive_list.append(drname)
return drive_list
def watch_drives(on_change: Callable[[dict],None] = print,poll_interval: int = 1):
def _watcher():
global prev
while True:
drives = get_drives()
if prev != drives:
on_change(drives)
play_audio()
prev = drives
sleep(poll_interval)
t = threading.Thread(target=_watcher)
t.start()
t.join()
if __name__ == '__main__':
prev = get_drives()
watch_drives(on_change=print)
我听不懂,但是每次下载开始并且FFmpeg开始调试所有内容(使用youtube-dl)时,都会出现几秒钟的控制台窗口,它们立即消失。我该如何完全禁用控制台,以至于FFmpeg也无法将其打开?
编辑:是的,我已经尝试在PyInstaller中使用--windowed
和-w
参数
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。