Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Kivy] Chagne a button's function after its first pressed
I'm making a hidden object game, and I decided to use Kivy because I wanted to try it out.
One of the triggers for finding one of the hidden objects is clicking on the text "Not here" after the player has clicked this button, I want the on_press function to be changed so that the button no longer does anything. when I run my current code I get the error 'AssertionError: None is not callable' in sdl2

here is my current code, the place I assign the dummy function 'nothing()' is in the clk() function
from import App
from kivy.uix.button import Button
from kivy.uix.boxlayout import BoxLayout
class myLayout(BoxLayout):
    def __init__(self, **kwargs):
        super(myLayout, self).__init__(**kwargs)

        global btn
        btn = Button(text = "Not here")


    def nothing(self):
        do = 'nothing'

    def clk(self, obj):
        print("you found one")

class GameApp(App):
    def build(self):
        mL = myLayout()
        self.title = "We don't have any chemical weapons"
        self.icon = "Hussein.ico"
        return mL
if __name__ == "__main__":
here's the full error
[INFO ] [Base ] Leaving application in progress... Traceback (most recent call last): File "C:/Users/youre/Desktop/project/", line 28, in <module> GameApp().run() File "C:\Program Files\Python37\lib\site-packages\kivy\", line 826, in run runTouchApp() File "C:\Program Files\Python37\lib\site-packages\kivy\", line 502, in runTouchApp EventLoop.window.mainloop() File "C:\Program Files\Python37\lib\site-packages\kivy\core\window\", line 727, in mainloop self._mainloop() File "C:\Program Files\Python37\lib\site-packages\kivy\core\window\", line 460, in _mainloop EventLoop.idle() File "C:\Program Files\Python37\lib\site-packages\kivy\", line 340, in idle self.dispatch_input() File "C:\Program Files\Python37\lib\site-packages\kivy\", line 325, in dispatch_input post_dispatch_input(*pop(0)) File "C:\Program Files\Python37\lib\site-packages\kivy\", line 231, in post_dispatch_input listener.dispatch('on_motion', etype, me) File "kivy\_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch File "C:\Program Files\Python37\lib\site-packages\kivy\core\window\", line 1360, in on_motion self.dispatch('on_touch_down', me) File "kivy\_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch File "C:\Program Files\Python37\lib\site-packages\kivy\core\window\", line 1376, in on_touch_down if w.dispatch('on_touch_down', touch): File "kivy\_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch File "C:\Program Files\Python37\lib\site-packages\kivy\uix\", line 460, in on_touch_down if child.dispatch('on_touch_down', touch): File "kivy\_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch File "C:\Program Files\Python37\lib\site-packages\kivy\uix\behaviors\", line 151, in on_touch_down self.dispatch('on_press') File "kivy\_event.pyx", line 703, in kivy._event.EventDispatcher.dispatch File "kivy\_event.pyx", line 1214, in kivy._event.EventObservers.dispatch File "kivy\_event.pyx", line 1138, in kivy._event.EventObservers._dispatch File "C:/Users/youre/Desktop/project/", line 19, in clk btn.bind(on_press=self.nothing()) File "kivy\_event.pyx", line 419, in kivy._event.EventDispatcher.bind AssertionError: None is not callable
Initially, in __init__, set:
self.func_to_run = self.clk

change button bind to:

then when you want to change what btn does:
self.func_to_run = self.new_func

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [Tkinter] Reset Button CPD3408 3 109 Jan-25-2019, 11:55 PM
Last Post: Larz60+
  [Tkinter] assigning two function for a single button prawesh05 3 108 Jan-16-2019, 10:39 PM
Last Post: Larz60+
  [Tkinter] button not defined OldManProgrammer 2 267 Nov-21-2018, 07:53 PM
Last Post: Larz60+
  Unable to return value from callback function of a button in Python Tkinter nilaybnrj 4 1,856 Aug-05-2018, 11:01 PM
Last Post: woooee
  [Tkinter] loop function when called from tkinter button click WantedStarling 5 780 Jul-13-2018, 06:12 PM
Last Post: nilamo
  Button not defined, why? gb_johnny 6 2,508 Nov-13-2017, 12:19 AM
Last Post: Windspar
  [Tkinter] Selected radio button in push button in Tkinter prashantfunde91 1 4,000 Jun-22-2017, 05:27 PM
Last Post: DeaD_EyE
  which button should be shown gray 1 1,049 Mar-30-2017, 11:57 AM
Last Post: Larz60+
  Gui Button click iFunKtion 1 1,081 Mar-21-2017, 01:46 PM
Last Post: Larz60+
  [Tkinter] Arguments in function for button command kristrek 14 6,726 Jan-11-2017, 09:16 PM
Last Post: kristrek

Forum Jump:

Users browsing this thread: 1 Guest(s)