Video player by Python tkinter, When I pause video, I cannot re-play
Question: Pause button will have no effect.
Reference:
Tkinter.Widget.after-method -
after(delay_ms, callback=None, *args)
Registers an callback that is called after a given time.
Tkinter.Widget.after_cancel-method -
after_cancel(id)
Cancels an callback.
To cancel
the allready queued events
for self.play_video
change the following:
def play_video(self): ... if self.pause: self.window.after_cancel(self.after_id) else: self.after_id = self.window.after(self.delay, self.play_video)
I would create another method for the play button callback. Something like this:
def play_start(self): self.pause = False self.play_video()
However, I would make sure you disable the play button if it's already playing. Otherwise, you could have multiple "instances" of play_video
going if the play button is pressed multiple times.
An alternative is to combine your play and pause button, so it toggles the value of self.pause
. Then you could have just one button with one callback function.