I've searched and read, but don't quite understand other posts and/or it doesn't reflect problem I have.
I've tried different things from similar posts, like this one: Passing variables, creating instances, self, The mechanics and usage of classes: need explanation, but apparantly, I don't understand classes, self quite enough (as can be seen I'm absolute beginner)
from tkinter import Tk, ttk, Frame, Label, StringVar, OptionMenu, Entry, Button, Toplevel
import pymysql as mdb
from functools import partial
from PIL import Image, ImageTk
class Home(object):
def __init__(self, master):
self.master = master
self.master.title("Control Panel")
self.master.configure(background="#%02x%02x%02x" % (61, 72, 73))
self.master.geometry("475x190")
self.master.resizable(width=False, height=False)
self.main_frame = Frame(master, background="#%02x%02x%02x" % (61, 72, 73))
self.main_frame.grid(row=1, column=1, columnspan=4, padx=15, pady=15)
load1 = Image.open('plan.jpg')
render1 = ImageTk.PhotoImage(load1)
self.button_plan = Button(self.main_frame, image=render1, command=self.b_clicked('Planning'))
self.button_plan.image = render1
self.button_plan.grid(row=1, column=1, padx=12)
self.label_plan = Label(self.main_frame, text='Planning', font='Calibri 9',
background="#%02x%02x%02x" % (61, 72, 73),
foreground="#%02x%02x%02x" % (255, 201, 14))
self.label_plan.grid(row=2, column=1, padx=12)
load2 = Image.open('consumption.jpg')
render2 = ImageTk.PhotoImage(load2)
self.button_consumption = Button(self.main_frame, image=render2, command=self.b_clicked('Consumption'))
self.button_consumption.image = render2
self.button_consumption.grid(row=1, column=2, padx=12)
self.label_consumption = Label(self.main_frame, text='Consumption', font='Calibri 9',
background="#%02x%02x%02x" % (61, 72, 73),
foreground="#%02x%02x%02x" % (255, 201, 14))
self.label_consumption.grid(row=2, column=2, padx=12)
def b_clicked(self, id):
self.button_id = id
self.master.withdraw()
self.second_w = Toplevel(self.master)
self.app = Second(self.second_w, self.button_id)
class Second(object):
def __init__(self, master, arg1):
self.master = master
self.master.title("Second")
self.master.configure(background="#%02x%02x%02x" % (61, 72, 73))
self.master.geometry("190x165")
self.master.resizable(width=False, height=False)
print(arg1)
root = Tk()
GUI = Home(root)
root.mainloop()
I would like to pass a variable value into another class. In this case I would like to get self.button_id value 'Planning' from class Home to be passed to class Second. Point is... I don't need just solution. I would really like to understand it and this would be a great opportunity to learn it on my own example!