Apr-18-2020, 06:21 AM
Hey folks,
I've got a very limited understanding of how to pass information through a function. I have a tkinter page with multiple buttons. (Just FYI I copied code from various google searches to make this work so I'm not even sure what **kwargs is doing for my purpose but I don't care at the moment that is not my question)
In this format I am curious how to give each button it's own text. I attempted using the variable 'button_label' but not sure how to pass this information into the class.
I also have an argument called 'which_button' and 'btnGPIO' which pass the information of which GPIO pin to toggle, but again not sure how to pass this info through the clicked function.
I'm sure this is fairly basic stuff but I cannot find a solution to either yet... any help is appreciated!!
I've got a very limited understanding of how to pass information through a function. I have a tkinter page with multiple buttons. (Just FYI I copied code from various google searches to make this work so I'm not even sure what **kwargs is doing for my purpose but I don't care at the moment that is not my question)
In this format I am curious how to give each button it's own text. I attempted using the variable 'button_label' but not sure how to pass this information into the class.
I also have an argument called 'which_button' and 'btnGPIO' which pass the information of which GPIO pin to toggle, but again not sure how to pass this info through the clicked function.
I'm sure this is fairly basic stuff but I cannot find a solution to either yet... any help is appreciated!!
from tkinter import * import raspberryGPIO functionsPage = Tk() functionsPage.geometry('1024x600') class Toggle(Frame): def __init__(self, master=None, **kwargs): Frame.__init__(self, master, **kwargs) self.btn = Button(self, text=button_label, width=20, height=5, bg="yellow", command=self.clicked(which_button=btnGPIO)) self.btn.grid(column=0, row=0, pady=10) def clicked(self, which_button): if self.btn['bg'] == "yellow": self.btn.configure(bg="red") GPIO.output(which_button, GPIO.LOW) else: self.btn.configure(bg="yellow") GPIO.output(which_button, GPIO.HIGH) btn1 = Toggle(functionsPage) btn1.grid() btn2 = Toggle(functionsPage) btn2.grid() functionsPage.mainloop()