python - get previous Entry -


i trying make tkinter widget remember previous entry. problem having button method made erases previous entry every time pressed.

from tkinter import *  class step1():     def __init__(self):         pass      def gettextbook(self):         temp = str(textbook.get())         textbook.delete(0, end)          x = " "         x += temp         print x       def equal_button(self):         print gettextbook(self)    root = tk() root.title("step1") root.geometry("600x600") s = step1()  app = frame(root) app.grid() label = label(app, text = "step1") label.grid()  textbook = entry(app, justify=right) textbook.grid(row=0, column = 0, columnspan = 3, pady = 5)  textbook2 = entry(app, justify=right)  textbook2.grid(row=1, column = 0, columnspan = 3, pady = 5)  button1 = button(app, text = "return", command = lambda: s.gettextbook()) button1.grid()   button2 = button(app, text="equal") button2.grid()  root.mainloop() 

the variable x in gettextbook() being overwritten every time set " ". try list instead, , append each entry list when button pressed:

from tkinter import *  root = tk()  textbooklist = []  def gettextbook():     textbooklist.append(textbook.get())     textbook.delete(0,end)     print textbooklist  textbook = entry(root) textbook.pack()  btn1 = button(root, text='return', command=gettextbook) btn1.pack()  root.mainloop() 

Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -