簡體   English   中英

如何在 Tkinter 中運行 mp4?

[英]How run an mp4 in Tkinter?

我一直在嘗試在 Tkinter 中運行 mp4,但在 --main--.py 和 runpy.py 中收到關於幾行錯誤的錯誤消息。 我是新手,這讓我很困惑,因為我花了好幾個小時試圖解決這個問題。 我的視頻的文件路徑也有問題,因此也將不勝感激! 這是我正在運行的代碼!

import tkinter as tk, threading
import imageio
from PIL import Image, ImageTk
⠀
video_name = "C:\Users\Jacob Kuhn\Videos\Rotomdex.mp4" #This is my video file path
video = imageio.get_reader(video_name)
⠀
def stream(label):
⠀
    for image in video.iter_data():
        frame_image = ImageTk.PhotoImage(Image.fromarray(image))
        label.config(image=frame_image)
        label.image = frame_image
⠀
if __name__ == "__main__":
⠀
    root = tk.Tk()
    my_label = tk.Label(root)
    my_label.pack()
    thread = threading.Thread(target=stream, args=(my_label,))
    thread.daemon = 1
    thread.start()
    root.mainloop()

和發送的錯誤。

Traceback (most recent call last):
 File "C:\Users\Jacob Kuhn\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main 
return _run_code(code, main_globals, None,
 File "C:\Users\Jacob Kuhn\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
File "c:\program files\microsoft visual studio\2022\community\common7\ide\extensions\microsoft\python\core\debugpy\__main__.py", line 45, in <module>
cli.main()
File "c:\program files\microsoft visual studio\2022\community\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 444, in main
run()
File "c:\program files\microsoft visual studio\2022\community\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 285, in run_file
runpy.run_path(target_as_str, run_name=compat.force_str("__main__"))
File "C:\Users\Jacob Kuhn\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 268, in run_path
code, fname = _get_code_from_file(run_name, path_name)
File "C:\Users\Jacob Kuhn\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 242, in _get_code_from_file
code = compile(f.read(), fname, 'exec')
File "C:\Users\Jacob Kuhn\source\repos\RotomDex\RotomDex\RotomDex.py", line 5
video_name = "C:\Users\Jacob Kuhn\Videos\Rotomdex.mp4" #This is my video file path
                                                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
Press any key to continue . . .

有人知道嗎?

在指定路徑時使用“/”正斜杠而不是反斜杠。 所以你會這樣寫:

C:/Users/Jacob Kuhn/Videos/Rotomdex.mp4

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM