如何使用pickle在QDialog上显示字典?

时间:2016-03-11 07:27:11

标签: python dictionary pickle

当我正在学习python时,我在显示字典方面遇到了问题。我的词典得到保存和检索,但没有在Qdialog上显示。 我在下面附上了我的代码。请解决这个问题。

def button_click(self):
    aa = {}
    aa["Name"] = str(self.lineEdit_name.text())
    aa["Address"] = str(self.lineEdit_address.text())

    return aa
    print aa

def retrieve(self):
    aa = self.use_file()
    if (aa != None):      
        self.lineEdit_name.setText(aa[self.lineEdit_name.text()])
        self.lineEdit_address.setText(aa["Address"])

    return aa

def save_file(self, parent=None):
    bbb = self.button_click()
    filename = QtGui.QFileDialog.getSaveFileName(parent, 'Save File', '/home/reshma/untitled.txt', filter= '*.txt')
    fileobj = open(filename,"w")
    pickle.dump(bbb, fileobj)
    #fileobj.close()

    print bbb

def use_file(self, parent=None):
    bbb = self.button_click()
    filename = QtGui.QFileDialog.getOpenFileName(parent, 'Open File', '/home/reshma/untitled.txt', filter= '*.txt')

    if os.path.isfile(filename):
        file = open(filename, "r+")
        infile= pickle.load(file)
        print infile
        return infile
    else:
        return None

0 个答案:

没有答案