tkinter bind label does not work | Sololearn: Learn to code for FREE!

+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

1/6/2020 10:47:46 PM

Sebastian Keßler

7 Answers

New Answer

+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

+9

Aymane Boukrouh [INACTIVE] Thank's. Now I can go forward and implement the functions for propper Output πŸ™Œ

+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)

+5

Aymane Boukrouh [INACTIVE] So... is your fix not the solution?

+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.

+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 ^_^

+4

Aymane Boukrouh [INACTIVE] Nice! I'll give this a review later when I'm at my laptop.