简体   繁体   中英

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

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) . 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. 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..." ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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