2016-08-17 15 views
-1

私はtkinterでアプリケーションを作成していますが、何らかの理由でTextのオブジェクトからget()関数を呼び出せません()クラス:エラーが発生しますtkinter(python 3.5)の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() 

ありがとう: はここに私のコードです!

+0

を使用

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

、代わりの

self.textinput.get() 

を言って2行にそれを回しました.grid(row = 0、column = 0) '' .grid() 'メソッドは' None'を返します。 self.textinput = tkinter.Text(); self.textinput.grid(...) ' –

答えて

0

Nevermind!私はそれを把握してしまった。代わりに

textinput = tkinter.Text().grid(row=0,column=0) 

を言って1行の私は) `tkinter.Text(

self.textinput.get('1.0','end-1c') 
関連する問題