不能腌制_tkinter.tkapp对象

时间:2016-10-11 22:38:11

标签: python tkinter

问题在于我无法在输入字段中挑选文本。我试着在'记录'功能。

错误:can't pickle _tkinter.tkapp objects

我想将数据保存在文件中然后阅读。

接口: enter image description here

#program to record and store your sports results

import shelve
from tkinter import *

class Application(Frame):
    '''GUI application ере displays menu for the programm'''
    def __init__(self, master):
        '''Initialize Frame'''
        super(Application, self).__init__(master)
        self.grid()
        self.create_widgets()

    def create_widgets(self):
        ''' Create widgets to get story information and to display story. '''

        self.fileDat = 'data'  

        # label date
        Label(self,
              text = "date:"
              ).grid(row = 0, column = 0, columnspan = 2, sticky = W)

        # field date
        self.date_ent = Entry(self)
        self.date_ent.grid(row = 1, column = 1, sticky = W)


        # label №
        Label(self,
              text = "№:"
              ).grid(row = 0, column = 3, columnspan = 2, sticky = W)

        # field №
        self.number_ent = Entry(self)
        self.number_ent.grid(row = 1, column = 4, sticky = W)


        # label km
        Label(self,
              text = "km:"
              ).grid(row = 2, column = 0, columnspan = 2, sticky = W)

        # field km
        self.km_ent = Entry(self)
        self.km_ent.grid(row = 3, column = 1, sticky = W)


        # label time
        Label(self,
              text = "time:"
              ).grid(row = 3, column = 0, columnspan = 2, sticky = W)

        # field time
        self.time_ent = Entry(self)
        self.time_ent.grid(row = 4, column = 1, sticky = W)


        # record button
        Button(self,
               text = "record training",
               command = self.record
               ).grid(row = 5, column = 0, sticky = W)


        # show training button
        Button(self,
               text = "show trining",
               command = self.tngDisplay
               ).grid(row = 5, column = 3, sticky = W)

        self.tngField = Text(self, width = 75, height = 10, wrap = WORD)
        self.tngField.grid(row = 6, column = 0, columnspan = 4)


    def listRecord( self):
        date = self.date_ent.get()
        km = self.km_ent.get()
        time = self.time_ent.get()
        tng = [date,km, time]
        return tng

    def record (self):

        tngList = self.listRecord
        tngNumber = self.number_ent.get()

        datFile = shelve.open(self.fileDat)
        datFile[tngNumber] = tngList
        #datFile['1'] = tngList
        datFile.sync()
        datFile.close()

    def tngDisplay (self):
        tng = ''

        self.tngField.delete(0.0, END)
        #i=0
        datFile = shelve.open(self.fileDat)
        for key, item in datFile.items():
            tng = str(key) + ': ' + str(item)
            # display trainings                                
            self.tngField.insert(0.0, tng)
            #i+=1


root = Tk()
root.title('RunForest')
app = Application(root)
root.mainloop()

0 个答案:

没有答案