【发布时间】:2018-04-17 03:55:30
【问题描述】:
我在 Windows 7 和 Python 2.7 上运行 the python-vlc example for tkinter 的精简版。
我正在尝试将点击记录到视频屏幕本身,没有任何按钮或额外的 UI。 但是,无论我在哪里尝试 .bind() 侦听器,VLC 似乎都会吞下所有输入,并且永远不会调用我的回调函数。
这里发布的代码可能太多了,但至少它应该运行。任何帮助表示赞赏!
#! /usr/bin/python
# -*- coding: utf-8 -*-
import vlc, sys, os, time, platform
import Tkinter as Tk
import ttk
def onClick():
print "a click was successful!"
class Player(Tk.Frame):
"""The main window has to deal with events.
"""
def __init__(self, parent, title=None, url=""):
Tk.Frame.__init__(self, parent)
self.parent = parent
self.url = url
self.player = None
self.videopanel = ttk.Frame(self.parent)
self.canvas = Tk.Canvas(self.videopanel,bg="blue")
#try to listen for clicks
self.videopanel.bind('<Button-1>', onClick)
self.canvas.bind('<Button-1>', onClick)
self.canvas.pack(fill=Tk.BOTH,expand=1)
self.videopanel.pack(fill=Tk.BOTH,expand=1)
# VLC player controls
self.Instance = vlc.Instance()
self.player = self.Instance.media_player_new()
self.parent.update()
self.Media = self.Instance.media_new(self.url)
self.player.set_media(self.Media)
# set the window id where to render VLC's video output
if platform.system() == 'Windows':
self.player.set_hwnd(self.GetHandle())
else:
self.player.set_xwindow(self.GetHandle()) # this line messes up windows
self.player.play()
def GetHandle(self):
return self.videopanel.winfo_id()
if __name__ == "__main__":
root = Tk.Tk()
player = Player(root, title="tkinter vlc", url="video.mp4")
player.bind('<Button-1>', onClick)
root.mainloop()
【问题讨论】: