首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Tkinter中运行mp4?

如何在Tkinter中运行mp4?
EN

Stack Overflow用户
提问于 2022-02-24 00:43:58
回答 1查看 113关注 0票数 0

我一直试图在Tkinter中运行一个mp4,并收到了一条关于main-..py和runpy.py中的几个行错误的错误消息。我是个新手,这让我很困惑,因为我花了好几个小时来解决这个问题。我也有一个问题,在文件路径为我的视频,所以在这方面的帮助也将非常感谢!这是我正在运行的代码!

代码语言:javascript
复制
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()

并发出了错误。

代码语言:javascript
复制
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 . . .

有人知道线索吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-02-24 01:01:07

在指定路径时使用'/‘正斜杠而不是后斜杠。所以你可以写这个代替:

代码语言:javascript
复制
C:/Users/Jacob Kuhn/Videos/Rotomdex.mp4
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71245751

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档