Access variable within a nested class in Python -


i'm having trouble title says. have code @ 1 point:

class eventadd:     def __init__(self):         class agendaevent:             def __init__(self, master):                 self.frame = frame(master, padx=10, pady=10) 

later on, outside of class eventadd, on same level eventadd, have:

def addevent():     instance = eventadd()     donebutton = button([problem area], text="done", command=done) 

where have typed [problem area] is, quite obviously, problem area. want create donebutton inside frame inside agendaevent inside eventadd. possible reference variable inside init inside class inside init inside class use this? if so, how?

i apologize programming sins may have committed. new programming , not yet sure best way go things are. suggestions welcome.

thanks in advance.

edit: full script:

from tkinter import * functools import partial   class eventadd:     def __init__(self):         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)             rem = button(this_instance.frame, text="remove", bg="lightblue",                  command=partial(remove_class, this_instance))             rem.grid(row=1, column=3)           def remove_class(instance):             instance.frame.destroy()             instance = ""          def done():             print('tbd')          window = tk()          addonebutton = button(window, text="+1", command=partial(addone, window))         addonebutton.grid(row=1, column=0)          window.mainloop()  def addevent():     instance = eventadd()     donebutton = button([problem area], text="done", command=done)     donebutton.pack()  def done():     print('tbd')  root = tk()  addeventbutton = button(root, text="add events", command=addevent) addeventbutton.pack()  root.mainloop() 

edit: error

exception in tkinter callback traceback (most recent call last):   file "c:\python27\lib\lib-tk\tkinter.py", line 1532, in __call__     return self.func(*args)   file "c:/users/john grady/pycharmprojects/dad's agenda/scripts/main.py", line 41, in addevent     instance = agendaevent(window)   file "c:/users/john grady/pycharmprojects/dad's agenda/scripts/main.py", line 6, in __init__     self.frame = frame(master, padx=10, pady=10)   file "c:\python27\lib\lib-tk\tkinter.py", line 2565, in __init__     widget.__init__(self, master, 'frame', cnf, {}, extra)   file "c:\python27\lib\lib-tk\tkinter.py", line 2086, in __init__     (widgetname, self._w) + + self._options(cnf)) tclerror: can't invoke "frame" command:  application has been destroyed 

it's hard understand you're trying accomplish. regardless, 1 problem going have should not calling tk() more once, , should ever call mainloop() once.

if need multiple windows need create instances of toplevel. solution requires destroying , recreating root window going hard right.


Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -