2016-09-12 6 views
-1

私はこのコードを書いています。このコードは、すべてのファイルが同じ日付を持っているかどうかをユーザに尋ねるもので、そうであれば、グリッド。 日付を入力すると、両方のウィンドウが消え、日付を保存します。 残念ながら私は最初の入力ボックスが消えてしまわないように管理していますが、この全手順の後で入力日付は再び[]になります。tkinterのtkinterは値を消してしまいます(python 3.4.3)

from tkinter import * 

    entry_date = [] 
      if amountfiles == 1: 
       def moredates(): 
        master.destroy() 

       def setdate(): 
        def entry_date(): 
         entry_date = e1.get() 
         entry_date = str(entry_date) 
         print("Date for all files is: ",entry_date) 
         master.destroy() 

        def quit(): 
         sys.exit() 

        master = Tk() 
        Label(master, text="Please enter date (format YYYYMMDD, i.e. 20160824): ").grid(row=0) 
        e1 = Entry(master) 
        e1.grid(row=0, column=1) 
        Button(master, text='Quit', command=master.destroy).grid(row=3, column=1, sticky=W, pady=4) 
        Button(master, text='Insert', command=entry_date).grid(row=2, column=1, sticky=W, pady=4) 
        mainloop() 

       master = Tk() 
       Label(master, text="Do all files have the same date?").grid(row=0) 
       Button(master, text='No...', command=moredates).grid(row=2, column=0, sticky=W, pady=4) 
       Button(master, text='Yes!', command=setdate).grid(row=1, column=0, sticky=W, pady=4) 
       Button(master, text='Close & Contiune', command=master.destroy).grid(row=3, column=0, sticky=W, pady=4) 
       mainloop() 
+0

本当にコードがインデントされていますか? –

答えて

1

master変数が機能setdate()に再割り当てされると、コールmaster.destroy()が唯一の新しいmaster、ない外master閉じます。関数setdate()を以下のように変更してみてください。

def setdate(): 
    def append_date(): 
     date = e1.get() # get the input entry date 
     entry_date.append(date) # save the input date 
     print("Date for all files is: ", date) 
     master.destroy() 

    top = Toplevel() # use Toplevel() instead of Tk() 
    Label(top, text="Please enter date (format YYYYMMDD, i.e. 20160824): ").grid(row=0) 
    e1 = Entry(top) 
    e1.grid(row=0, column=1) 
    Button(top, text='Quit', command=master.destroy).grid(row=3, column=1, sticky=W, pady=4) 
    Button(top, text='Insert', command=append_date).grid(row=2, column=1, sticky=W, pady=4) 
    master.wait_window(top) # use Tk.wait_window() 
+0

Tkinterコールバックの例外 トレースバック(最新の最後の呼び出し): ファイル "C:\ Python34 \ lib \ tkinter \ __ init__.py"、行1533、__call__ファイル return self.func * args) entry_dateのファイル "C:\ Users \ path" entry_date.append(date)#入力日を保存する AttributeError: 'function'オブジェクトに属性 'append''がありません – cesco

+0

私も試しましたappendの代わりに.insertを使用しますが、同じエラーメッセージが表示されます。 – cesco

+0

私のコードは 'entry_date()'関数を 'append_date()'に変更しました。 – acw1668

関連する問題