Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将值从一个Tkinter帧保留到另一个Tkinter帧_Python_Python 3.x_Class_Tkinter - Fatal编程技术网

Python 将值从一个Tkinter帧保留到另一个Tkinter帧

Python 将值从一个Tkinter帧保留到另一个Tkinter帧,python,python-3.x,class,tkinter,Python,Python 3.x,Class,Tkinter,我试图在Tkinter中将变量值从一个帧传递到另一个帧,但它返回的是空值 A类: class a(tk.Frame): def __init__(self,parent,controller): tk.Frame.__init__(self,parent) self.controller=controller self.logVar=tk.StringVar() tk.Entry(self, textvariable=self.log

我试图在Tkinter中将变量值从一个帧传递到另一个帧,但它返回的是空值

A类:

class a(tk.Frame):
    def __init__(self,parent,controller):
        tk.Frame.__init__(self,parent)
        self.controller=controller


    self.logVar=tk.StringVar()

    tk.Entry(self, textvariable=self.logVar,width=4,show="*").grid(row=1,column=1)  
B类:

class b(tk.Frame):
def __init__(self,parent,controller):
    tk.Frame.__init__(self,parent)
    self.controller=controller
    frame=controller.frames['a']
    pin=frame.logVar.get()
    print(pin)
    tk.Label(self,text=pin).grid(row=0,column=1)

没有显示任何错误,它只是返回一个空字符串。

帧是在开始时创建的,甚至在您看到窗口之前创建的,所以在您将文本放入条目之前,它会从条目中获取值。您必须创建一个函数,当您更改帧时,该函数将获取值并运行它。几天前也有类似的问题。