WX.EVT_LISTBOX_DCLICK 点击不同的视频
WX.EVT_LISTBOX_DCLICK click for different video
我在点击列表框时出现问题,在我的程序中,我点击列表框会出现一个视频。我在数据库中做了一个示例 "name_link" ,它将出现在列表框中。视频 1、视频 2、视频 3。每个 name_link 都有不同的视频。但是,每次我单击其中一个 name_link 时,都会发生这种情况,该视频仅出现 Video3。当我点击name_link video1 video2 emergeing or always Video3。我被困在这个部分了。
点击期间此部分:
self.opt = wx.ListBox(pan1, -1, pos=(10, 210), size=(480, 250), style= wx.TE_MULTILINE | wx.BORDER_SUNKEN)
def playFile(self, event):
self.player.Play()
def OnEnter(self, event):
self.opt.SetLabel(self.PatMatch())
def PatMatch(self):
con = sqlite3.connect('test.db')
with con:
cur = con.cursor()
for row in cur.execute("Select * From Video"):
klmt = self.inpt.GetValue()
if row[1] in klmt.lower():
self.opt.Append(row[2])
self.player.Load(row[4])
return self.Bind(wx.EVT_LISTBOX_DCLICK, self.playFile, self.op)
数据库是这样的:
id word name_link explain link
--- ------ ----------- --------- --------
1 python Video1 test C:\Users\Ihsan\Downloads\Video1.MP4
2 python Video2 test1 C:\Users\Ihsan\Downloads\Video2.MP4
3 python Video3 test2 C:\Users\Ihsan\Downloads\Video3.MP4
您应该对列表中的项目使用 ClientData
。检查以下快速代码。通过使用 ClientData
,您可以为项目显示不同的标签并为每个项目存储必要的数据。
import wx
db = [
{"id": 1, "name_link": "Video 1", "link": "C:\first_video.mp4"},
{"id": 2, "name_link": "Video 2", "link": "C:\second_video.mp4"},
{"id": 3, "name_link": "Video 3", "link": "C:\third_video.mp4"},
]
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, parent=None, title="List of Videos")
self.opt = wx.ListBox(self)
self.fillOpt()
self.opt.Bind(wx.EVT_LISTBOX_DCLICK, self.startVideo)
self.Show()
def fillOpt(self):
for row in db:
self.opt.Append(row['name_link'], row['link']) # Label, ClientData
def startVideo(self, event):
wx.MessageBox(parent=self, message=event.GetClientData(), caption="Video")
if __name__ == '__main__':
app = wx.App(False)
frame = MyFrame()
app.MainLoop()
我在点击列表框时出现问题,在我的程序中,我点击列表框会出现一个视频。我在数据库中做了一个示例 "name_link" ,它将出现在列表框中。视频 1、视频 2、视频 3。每个 name_link 都有不同的视频。但是,每次我单击其中一个 name_link 时,都会发生这种情况,该视频仅出现 Video3。当我点击name_link video1 video2 emergeing or always Video3。我被困在这个部分了。
点击期间此部分:
self.opt = wx.ListBox(pan1, -1, pos=(10, 210), size=(480, 250), style= wx.TE_MULTILINE | wx.BORDER_SUNKEN)
def playFile(self, event):
self.player.Play()
def OnEnter(self, event):
self.opt.SetLabel(self.PatMatch())
def PatMatch(self):
con = sqlite3.connect('test.db')
with con:
cur = con.cursor()
for row in cur.execute("Select * From Video"):
klmt = self.inpt.GetValue()
if row[1] in klmt.lower():
self.opt.Append(row[2])
self.player.Load(row[4])
return self.Bind(wx.EVT_LISTBOX_DCLICK, self.playFile, self.op)
数据库是这样的:
id word name_link explain link
--- ------ ----------- --------- --------
1 python Video1 test C:\Users\Ihsan\Downloads\Video1.MP4
2 python Video2 test1 C:\Users\Ihsan\Downloads\Video2.MP4
3 python Video3 test2 C:\Users\Ihsan\Downloads\Video3.MP4
您应该对列表中的项目使用 ClientData
。检查以下快速代码。通过使用 ClientData
,您可以为项目显示不同的标签并为每个项目存储必要的数据。
import wx
db = [
{"id": 1, "name_link": "Video 1", "link": "C:\first_video.mp4"},
{"id": 2, "name_link": "Video 2", "link": "C:\second_video.mp4"},
{"id": 3, "name_link": "Video 3", "link": "C:\third_video.mp4"},
]
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, parent=None, title="List of Videos")
self.opt = wx.ListBox(self)
self.fillOpt()
self.opt.Bind(wx.EVT_LISTBOX_DCLICK, self.startVideo)
self.Show()
def fillOpt(self):
for row in db:
self.opt.Append(row['name_link'], row['link']) # Label, ClientData
def startVideo(self, event):
wx.MessageBox(parent=self, message=event.GetClientData(), caption="Video")
if __name__ == '__main__':
app = wx.App(False)
frame = MyFrame()
app.MainLoop()