我已经在Linux上使用Page GUI构建器创建了gui。它有一个框架和一个画布。我正在尝试在其中一个帧上播放视频。 现在,当我运行代码时,我得到_tkinter.TclError:未知选项“ -image”错误。我尝试了类似的问题及其解决方案,但没有一个起作用。 我正在使用Python3。为了构建GUI,使用了tkinter。
#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# GUI module generated by PAGE version 4.22
# in conjunction with Tcl version 8.6
# Oct 25, 2019 12:16:56 PM IST platform: Linux
import sys
try:
import Tkinter as tk, threading
except ImportError:
import tkinter as tk, threading
try:
import ttk
py3 = False
except ImportError:
import tkinter.ttk as ttk
py3 = True
import video_gui_support
import imageio
from PIL import Image, ImageTk
def vp_start_gui():
'''Starting point when module is the main routine.'''
global val, w, root
root = tk.Tk()
top = Toplevel1 (root)
video_gui_support.init(root, top)
root.mainloop()
w = None
def create_Toplevel1(root, *args, **kwargs):
'''Starting point when module is imported by another program.'''
global w, w_win, rt
rt = root
w = tk.Toplevel (root)
top = Toplevel1 (w)
video_gui_support.init(w, top, *args, **kwargs)
return (w, top)
def destroy_Toplevel1():
global w
w.destroy()
w = None
class Toplevel1:
def stream(self, label):
video_name = "intro.mp4" #This is your video file path
video = imageio.get_reader(video_name)
for image in video.iter_data():
frame_image = ImageTk.PhotoImage(Image.fromarray(image))
label.configure(image=frame_image)
label.image = frame_image
def __init__(self, top=None):
print("Started")
'''This class configures and populates the toplevel window.
top is the toplevel containing window.'''
_bgcolor = '#d9d9d9' # X11 color: 'gray85'
_fgcolor = '#000000' # X11 color: 'black'
_compcolor = '#d9d9d9' # X11 color: 'gray85'
_ana1color = '#d9d9d9' # X11 color: 'gray85'
_ana2color = '#ececec' # Closest X11 color: 'gray92'
top.geometry("1920x1012+0+0")
top.title("New Toplevel")
self.Frame1 = tk.Frame(top)
self.Frame1.place(relx=0.531, rely=0.01, relheight=0.983, relwidth=0.466)
self.Frame1.configure(relief='groove')
self.Frame1.configure(borderwidth="2")
self.Frame1.configure(relief="groove")
self.Frame1.configure(width=895)
# Code to run video file
thread = threading.Thread(target=self.stream, args=(self.Frame1,))
thread.daemon = 1
thread.start()
self.Canvas1 = tk.Canvas(top)
self.Canvas1.place(relx=0.005, rely=0.01, relheight=0.982
, relwidth=0.521)
self.Canvas1.configure(borderwidth="2")
self.Canvas1.configure(relief="ridge")
self.Canvas1.configure(selectbackground="#c4c4c4")
self.Canvas1.configure(width=1001)
if __name__ == '__main__':
vp_start_gui()
出现错误-
Started
Exception in thread Thread-2:
Traceback (most recent call last):
File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "video_gui.py", line 80, in stream
label.configure(image=frame_image)
File "/usr/lib/python3.6/tkinter/__init__.py", line 1485, in configure
return self._configure('configure', cnf, kw)
File "/usr/lib/python3.6/tkinter/__init__.py", line 1476, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: unknown option "-image"
答案 0 :(得分:1)
您正在将Frame
的实例传递给stream
。这是参数label
。然后,您尝试配置该框架的图像,但是框架没有image
属性。
如果要显示图像,则需要创建Label
的实例或其他支持图像的小部件。