0

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")
D.Y
  • 19
  • 2

1 Answers1

0

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: \u00a9 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..." ).

patthoyts
  • 32,320
  • 3
  • 62
  • 93