I am creating a Python program (3.4.3) - tkinter and wondering if it's possible to reference def(self.get_details) from inside another classfor a button command. I could not find the answer to this problem anywhere, so I decided that I would just ask.
Example:
import tkinter as tk
...
class Widgets(tk.Frame):
def __init__(self, parent):
tk.Frame.__init___(self, parent)
self.parent = parent
self.initUI()
def initUI():
self.button = tk.Button(command=App(get_details))
self.button.pack()
class PopUp(tk.TopLevel): ....
class App(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent)
self.parent = parent
self.initUI()
def get_details(self):
def initUI(self):
self.parent.title("My Application")
self.style = Style()
self.style.theme_use("default")
self.pack()
self.widgets = Widgets(self)
self.widgets.pack(side="top", anchor="center", fill="both", expand=True)
if __name__ == "__main__":
root = tk.Tk()
App(root).pack(side="top", fill="both", expand=True)
root.resizable(0,0)
root.mainloop()
So I would like a button that belongs to a class Widgets()to invoke a command def get_details(self)that belongs to a class App()that has a class Widgets()packed inside it.
I hope that I am quite descriptive, it is rather difficult to formulate this problem. I'm still new to Python in general. Thank!
Edit:
, self.parent.get_details(), ! , tkinter Widgets() def get_details(), : self.button, :
AttributeError: 'App' object has no attribute 'button'
, : self.parent.button, :
AttributeError: 'tkapp' object has no attribute 'button'
/ ? !