简体   繁体   English

单击tkinter上的按钮后如何播放视频

[英]how to play a video after clicking a button on tkinter

I'm trying to make a video play after a button is clicked, but its not working. 我试图在单击按钮后播放视频,但是它不起作用。 The error I get is SyntaxError (unicode error) 'unicodeescape' codec can't decode bytes in positiion 2-3: truncated\\UXXXXXXXX escape 我得到的错误是SyntaxError(unicode错误)'unicodeescape'编解码器无法解码位置2-3中的字节:截断\\ UXXXXXXXX转义

rb1 = tk.Button(self, text = "Play", command=self.video).pack()

def video(self):
    import os

    os.system("C:\Users\Tim\Documents\Bicep.mp4")

Your quoting of the file path is causing this error. 您对文件路径的引用导致此错误。 In python strings a backslash is used as an escape character to provide a means to enter special characters like newlines and unicode characters (eg: \© for the copyright character) . 在python字符串中,反斜杠用作转义字符,以提供一种输入特殊字符(如换行符和unicode字符)的方式(例如:\\ u00a9为版权字符)。 So the "\\Us" sequence is translated into an attempt to read a unicode character definition that is invalid as 's' is not a hexadecimal digit. 因此, "\\Us"序列会转换为尝试读取无效的Unicode字符定义的尝试,因为s不是十六进制数字。 You should either escape the backslashes ("c:\\Users\\Tim\\...") or use the raw string marker to indicate this string should not have escape code translations performed (ie: r"C:\\Users\\Tim..." ). 您应该转义反斜杠(“ c:\\ Users \\ Tim \\ ...”)或使用原始字符串标记来指示此字符串不应执行转义代码转换(即:r“ C:\\ Users \\ Tim.。 。”)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM