python - Store class variable in dictionary -


i making program have box receives 2 inputs, event name , time allocated event, , later output list of events have been added. class input boxes:

class agendaevent:     def __init__(self, master):         self.frame = frame(master, padx=10, pady=10)         self.frame.grid()         self.name = entry(self.frame)         self.name.grid(row=1, column=0)         self.time = entry(self.frame, width=10)         self.time.grid(row=1, column=1, padx=5) 

i new programming, believe correct way store name , time in dictionary.

there multiple instances of class running @ same time , more run after these have been stored. preferable have them stored in same dictionary.

however, not know how store self variables in dictionary later access outside of class. possible? if so, how? if not, how store variables in way accessed in separate function?

edit: minimal code (i think) needed replicate issue:

from tkinter import * functools import partial   class agendaevent:      def __init__(self, master):         self.frame = frame(master, padx=10, pady=10)         self.frame.grid()         self.name = entry(self.frame)         self.name.grid(row=1, column=0)         self.time = entry(self.frame, width=10)         self.time.grid(row=1, column=1, padx=5)         self.label1 = label(self.frame, text="event name")         self.label1.grid(row=0, column=0)         self.label2 = label(self.frame, text="minutes")         self.label2.grid(row=0, column=1)  def addone(master):     this_instance = agendaevent(master)  def addevent():     window = toplevel()     addonebutton = button(window, text='+1', command=partial(addone, window))     addonebutton.grid(row=0, column=0, pady=5)     donebutton = button(window, text='done', command=partial(done, window))     donebutton.grid(row=1, column=0, pady=3)  def done(windowinstance):      #this thinking     #the code storing information     #should because should store     #when done button pressed.     #this may not way it,     #i don't know.       windowinstance.destroy()     windowinstance = ""    root = tk()   addeventbutton = button(root, text="add events", command=addevent) addeventbutton.pack()  root.mainloop() 

i think need store agendaevent instances create in list; can iterate on list afterwards:

from tkinter import * functools import partial  events = []  # place store instances  class agendaevent:      ...   def addone(master):     events.append(agendaevent(master))  # store new instance in list  def addevent():     ...  def done(windowinstance):     event in events:         ...  # use event.time, event.date, etc.     windowinstance.destroy()     windowinstance = ""  root = tk()  addeventbutton = button(root, text="add events", command=addevent) addeventbutton.pack()  root.mainloop() 

you may need clear list in done, if section can called again.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -