+ 24

tkinter bind label does not work

I am writing a GUI with tkinter. It should be strictly OOP. The problem is that the labels execute the functions after binding one time. But they should call them every time I click the labels. Here is the code example https://code.sololearn.com/c5Z7mM9V51jT/?ref=app

6th Jan 2020, 10:47 PM
Sebastian Keßler
Sebastian Keßler - avatar
7 Respostas
+ 14
Sebastian Keßler you have 2 mistakes: 1. You were binding the function call (which returns none, it just prints), so it was executed before the label was even clicked, right when you started you program. # Fix: remove the parenthesis 2. Even when you remove them, it will still not work, because by default, the class will pass self argument to the function, and will produce an error, saying output_1() takes 0 positional argument, but one was given. # Fix: To ignore the self argument, use: self.bind('<1>', lambda self: funk()) Here is the code: https://code.sololearn.com/cRQ5162RS0s9/?ref=app
6th Jan 2020, 11:13 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 9
Aymane Boukrouh [INACTIVE] Thank's. Now I can go forward and implement the functions for propper Output 🙌
7th Jan 2020, 5:24 AM
Sebastian Keßler
Sebastian Keßler - avatar
+ 7
David Carroll my fix is technically the solution, but all this does is print the result to console whenever you click the labels (which is what he wants I think), but not the GUI itself (because his functions print only, so I didn't change it)
6th Jan 2020, 11:20 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 5
Aymane Boukrouh [INACTIVE] So... is your fix not the solution?
6th Jan 2020, 11:16 PM
David Carroll
David Carroll - avatar
+ 4
Aymane Boukrouh [INACTIVE] no, it's not running on my Laptop. Does not matter If I start it from the shell or in IDLE.
6th Jan 2020, 11:11 PM
Sebastian Keßler
Sebastian Keßler - avatar
+ 4
Sebastian Keßler sorry I forgot that I fixed them before running the code 😂😂 it was a natural test to do and I kept thinking wth is wrong ^_^
6th Jan 2020, 11:14 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 4
Aymane Boukrouh [INACTIVE] Nice! I'll give this a review later when I'm at my laptop.
6th Jan 2020, 11:15 PM
David Carroll
David Carroll - avatar