Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/352.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
Can';t从tkinter(python 3.5)中的Text()对象获取()_Python_Object_Tkinter_Python 3.5_Nonetype - Fatal编程技术网

Can';t从tkinter(python 3.5)中的Text()对象获取()

Can';t从tkinter(python 3.5)中的Text()对象获取(),python,object,tkinter,python-3.5,nonetype,Python,Object,Tkinter,Python 3.5,Nonetype,我正在tkinter中制作一个应用程序,由于某种原因,我无法从Text()类的对象调用函数“get()”:我得到了错误 AttributeError: 'NoneType' object has no attribute 'get' 我做错了什么? 这是我的密码: 1 import tkinter 2 3 4 class Main(): 5 6 def __init__(self): 7 #Defining Variables: 8

我正在tkinter中制作一个应用程序,由于某种原因,我无法从Text()类的对象调用函数“get()”:我得到了错误

AttributeError: 'NoneType' object has no attribute 'get'
我做错了什么? 这是我的密码:

  1 import tkinter
  2 
  3 
  4 class Main():
  5 
  6     def __init__(self):
  7         #Defining Variables:
  8 
  9         background_color = '#%02x%02x%02x' % (223,219,195)
 10         menubar_color = '#%02x%02x%02x' % (191, 167, 126)
 11         menubar_active = '#AB936A'
 12 
 13         #Creating Window:
 14         root = tkinter.Tk()
 15         root.geometry('1000x600')
 16         root.configure(background=background_color)
 17 
 18         #Menu:
 19         menubar = tkinter.Menu(root,bg=menubar_color,activebackground=menuba    r_active,borderwidth=0,font='quicksand.otf')
 20         menubar.add_command(label='Open',command=self.open_file)
 21         menubar.add_cascade(label='Save')
 22         menubar.add_cascade(label='Save As')
 23         menubar.add_cascade(label='New File')
 24 
 25         root.config(menu=menubar)
 26 
 27         #TextEntry Box:
 28         self.textinput = tkinter.Text().grid(row=0,column=0)
 29         root.mainloop()
 30 
 31     def open_file(self):
 32         text = self.textinput.get()
 33         print(text)
 34 
 35 if __name__ == '__main__':
 36     Main()

谢谢你的帮助

别客气!我碰巧弄明白了。而不是一句话

textinput = tkinter.Text().grid(row=0,column=0)
我把它变成两行,说

self.textinput = tkinter.Text()
self.textinput.grid(row=0,column=0)
而不是

self.textinput.get()
我曾经

self.textinput.get('1.0','end-1c')
tkinter.Text();self.textinput.grid(…)