Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.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 3.x 返回Tkinter控制变量的引用_Python 3.x_Variables_Tkinter_Return_Controls - Fatal编程技术网

Python 3.x 返回Tkinter控制变量的引用

Python 3.x 返回Tkinter控制变量的引用,python-3.x,variables,tkinter,return,controls,Python 3.x,Variables,Tkinter,Return,Controls,我不是一个有经验的程序员,所以如果我问了一个基本的问题,请提前道歉。我正在使用for循环打印tkinter条目,并试图将这些条目的引用返回给调用函数。但是当我尝试在条目中键入文本时,它总是返回空字符串?所以我的问题是,在python中是否可以返回控制变量的引用?还是我使用了错误的方法 def data_entry_txtfield(self,rn,cn,pu,pd): # Creates the Entry to enter data - rn is the row an

我不是一个有经验的程序员,所以如果我问了一个基本的问题,请提前道歉。我正在使用for循环打印tkinter条目,并试图将这些条目的引用返回给调用函数。但是当我尝试在条目中键入文本时,它总是返回空字符串?所以我的问题是,在python中是否可以返回控制变量的引用?还是我使用了错误的方法

    def data_entry_txtfield(self,rn,cn,pu,pd):
        # Creates the Entry to enter data - rn is the row and cn is column 
        # pd and pu are padding up and padding down
        entry = tk.StringVar()
        tk.Entry(self.inputlab,width=32,bg=entrycolor,textvariable=entry)
        entry.grid(column=cn,row=rn,pady=(pu,pd))
        return entry



    tbtlocationentry = self.data_entry_txtfield(9,4,0,12)
    text = tbtlocationentry.get()
    print(text)`

这段代码中有很多错误,比如底线您使用self.data\u entry\u txtfield调用函数,但您不需要self。除非你在课堂上使用。此外,条目还需要一个变量名,以便能够更改其中的内容。我已经修复了一些错误,下面是代码

def data_entry_txtfield(self,rn,cn,pu,pd):
        # Creates the Entry to enter data - rn is the row and cn is column 
        # pd and pu are padding up and padding down
        entry = tk.StringVar()
        ety = tk.Entry(self.inputlab,width=32,bg=entrycolor,textvariable=entry)
        ety.grid(column=cn,row=rn,pady=(pu,pd))
        return entry



    tbtlocationentry = self.data_entry_txtfield(9,4,0,12)
    text = tbtlocationentry.get()
    print(text)
我已经离开了自我。因为我假设你在一个类中使用这个