0

I want to make a button that when I clicked on it, that button will show me the whole info in the file.

let say i have this code this code can receive the info

from tkinter import *

def myexit():
    app.destroy()
def save():
    info = {}
    info['Name'] = entry_name.get()
    info['Family'] = entry_family.get()
    if country1.get() == 1:
        info['Country_1'] = 'Italy'
    elif country1.get() == 2:
        info['Country_1'] = 'France'
    elif country1.get() == 3:
        info['Country_1'] = 'Germany'
    if country2.get() == 1:
        info['Country_2'] = 'Romania'
    elif country2.get() == 2:
        info['Country_2'] = 'Greek'
    elif country2.get() == 3:
        info['Country_2'] = 'Poland'
    info['Age'] = spin_age.get()
    if left_hand.get() == 1:
        info['Left_hand'] = 'is left hand'
    else:
        info['Left_hand'] = 'is right hand'
    f = open('information', 'a')
    f.write(str(info))
    f.write('\n')
    f.close()
app = Tk()
app.geometry('400x300')
spin_age = Spinbox(app, from_ = 1, to = 100, bg='pink', state='readonly')

label_name = Label(app, text='name: ')
label_family = Label(app, text='family: ')
label_name.grid(row = 1, column=1)
label_family.grid(row = 2, column=1)
entry_name = Entry(app)
entry_family = Entry(app)
entry_name.grid(row=1, column=2)
entry_family.grid(row=2, column=2)
country1 = IntVar()
country2 = IntVar()
rb_italy = Radiobutton(app, text='Italy', variable=country1, value = 1)
rb_france = Radiobutton(app, text='France', variable=country1, value = 2)
rb_germany = Radiobutton(app, text='Germany', variable=country1, value = 3)
rb_romania = Radiobutton(app, text='Romania', variable=country2, value = 1)
rb_greek = Radiobutton(app, text='Greek', variable=country2, value = 2)
rb_poland = Radiobutton(app, text='Poland', variable=country2, value=3)
rb_italy.grid(row = 3, column=1, sticky='W')
rb_france.grid(row = 4, column=1, sticky='W')
rb_germany.grid(row = 5, column=1, sticky='W')
rb_romania.grid(row = 3, column=2, sticky='W', padx=10)
rb_greek.grid(row = 4, column=2, sticky='W', padx=10)
rb_poland.grid(row = 5, column=2, sticky='W', padx=10)
left_hand = IntVar()
chbox_left_hand = Checkbutton(app, text='I am left hand', variable=left_hand)
chbox_left_hand.grid(row = 6, column=1, pady=10)
btnExit = Button(app, text='Exit', command=myexit)
btnsave = Button(app, text='save', command=save)
spin_age.grid(row=1, rowspan=2, column=3, sticky='NS')
btnExit.grid(row=100, column=1)
btnsave.grid(row=100, column=2)
btnread = Button(app , text = 'saved info' , command = readbtn)
btnread.place(x = 70 , y = 200)
app.mainloop()

the save button well save the info i gave but i need a button to read the info

Art
  • 2,836
  • 4
  • 17
  • 34
  • To read saved info, you need to do the exact opposite to what you did when you saved it. So open the file, read its contents, [convert the string to a dict](https://stackoverflow.com/questions/988228/convert-a-string-representation-of-a-dictionary-to-a-dictionary) and set the widgets to correspond to the values in the dict. What have you tried and which part exactly do you need help with? – fhdrsdg Sep 01 '21 at 11:57
  • Please trim your code to make it easier to find your problem. Follow these guidelines to create a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – Community Sep 04 '21 at 09:18

0 Answers0