[Tkinter] How to add an argument to a buttons command call - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [Tkinter] How to add an argument to a buttons command call (/thread-18254.html) |
How to add an argument to a buttons command call - petterg - May-10-2019 Hi! using Python 3.6 and Tkinter Im calling a method with a button. The method will change text on a label Here is my button: self.button5 = Button(middleframe6, text="Configure machine", command=self.ReceiptFormat, relief=RAISED)which calls the method: def ReceiptFormat(self, *args): self.labelwindow['text'] = "Please select receipt Logo"The label will get the new text self.labelwindow = Label(master) self.labelwindow.place(relx=0.45, rely=0.4, relwidth=0.47, relheight=0.47)This works fine, but the problem is when im passing in an argument from the command. So im doing this: self.button5 = Button(middleframe6, text="Configure RVM", command=self.ReceiptFormat("text"), relief=RAISEDThe methode im calling def ReceiptFormat(self, confirm, *args): newtext = confirm self.labelwindow['text'] = newtextWhen im calling the method with the argument i get the following error message "AttributeError: 'SendT70' object has no attribute 'labelwindow'" Any idead why i cant change the label text when im using arguments when calling the method? RE: Calling methode with argument - Yoriz - May-10-2019 To add arguments to a function called as a command you can use partial from functools from functools import partial self.button5 = Button(middleframe6, text="Configure RVM", command=partial(self.ReceiptFormat, "text"), relief=RAISED RE: How to add an argument to a buttons command call - petterg - Jun-20-2019 That works, thanks! |