我能够将数据从一个类帧移动到另一个类帧,遗憾的是,我无法更新新帧中的文本。我只能将新数据打包到原始包装
之下class LabelApp(tk.Frame):
def __init__(self, master, xy_motion=[-1,-1]):
tk.Frame.__init__(self, master )
self.pack()
print('LapApp: ' + str(xy_motion[0]))
self.master = master
self.xy_motion=xy_motion
self.xlabel = tk.Label(text=self.xy_motion[0])
self.xlabel.pack()
def update_label(self, xy_motion ):
self.xlabel.config(text=xy_motion[0])
上面的print语句显示正确的数据
传递数据的代码
class VideoDisplayApp(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
self.pack()
self.master = master
self.image_label = tk.Label(master=self.master) # label for the vide.
..
.
.
def motion(self, event):
x, y = event.x, event.y
self.xy_motion = [x,y]
print('{}, {}'.format(x, y))
self.motion=tk.Frame(self.master)
self.app = LabelApp(self.motion, self.xy_motion )
主窗口
class MainWindow(tk.Frame):
def __init__(self, master):
tk.Frame.__init__(self, master)
self.pack(padx=15, pady=15)
self.master.title("Mob")
self.master.resizable(False, False)
self.master.tk_setPalette(background='#e6e6e6')
frame_video = tk.Frame(self)
frame_video.grid(row=0, column=0)
# frame_video.geometry("200x200")
VideoDisplayApp(frame_video)
#
frame_bottom = tk.Frame(self)
frame_bottom.grid(row=1, column=0)
LabelApp(frame_bottom)
#
frame_left = tk.Frame(self)
frame_left.grid(row=0, column=1)
ClickOnFrame(frame_left)