title: How to assign a function to a kivyMD button
body: <p>I'm new to kivy and kivymd and I have a problem with it. The thing is that I need to assign a function to a KivyMD RectangleFlatButton to open a website, but I don't know how to do that. Please show me how.</p>
  <p>Here's what I have tried;</p>
  <pre><code>from kivy.lang import Builder
  from kivy.uix.boxlayout import BoxLayout
  from kivy.properties import ObjectProperty
  
  from kivymd.app import MDApp
  
  import webbrowser
  
  class func():
      def open():
          webbrowser.open('google.com')
  
  KV = '''
  &lt;ContentNavigationDrawer&gt;:
      orientation: &quot;vertical&quot;
      padding: &quot;8dp&quot;
  
      ScrollView:
  
          MDList:
  
              MDLabel:
                  text: &quot;App&quot;
                  font_style: &quot;H3&quot;
                  size_hint_y: None
                  height: self.texture_size[1]
  
              OneLineListItem:
                  text: &quot;1&quot;
                  on_press:
                      root.nav_drawer.set_state(&quot;close&quot;)
                      root.screen_manager.current = &quot;scr 1&quot;
  
              OneLineListItem:
                  text: &quot;2&quot;
                  on_press:
                      root.nav_drawer.set_state(&quot;close&quot;)
                      root.screen_manager.current = &quot;scr 2&quot;
  
              OneLineListItem:
                  text: &quot;3&quot;
                  on_press:
                      root.nav_drawer.set_state(&quot;close&quot;)
                      root.screen_manager.current = &quot;scr 2&quot;
  
  
  Screen:
      pos: 0, root.height - 591
  
      MDToolbar:
          id: toolbar
          pos_hint: {&quot;top&quot;: 1}
          elevation: 10
          title: &quot;App&quot;
          left_action_items: [[&quot;menu&quot;, lambda x: nav_drawer.set_state(&quot;open&quot;)]]
  
      NavigationLayout:
          x: toolbar.height
  
          ScreenManager:
              id: screen_manager
  
              Screen:
                  name: &quot;scr 1&quot;
  
                  BoxLayout:
                      orientation: &quot;vertical&quot;
                      padding: &quot;10db&quot;
                  
                      MDLabel:
                          text: &quot;Google&quot;
                          font_style: &quot;H3&quot;
                          halign: &quot;center&quot;
  
                      MDLabel:
                          text: &quot;Go to google!!!&quot;
                          font_style: &quot;Body2&quot;
                          halign: &quot;center&quot;
  
                      MDRectangleFlatButton:
                          id: &quot;button1&quot;
                          text: &quot;Go to Google&quot;
                          pos_hint: {&quot;center_x&quot;: 0.5}
                          on_press: func.open()
  
              Screen:
                  name: &quot;scr 2&quot;
  
                  MDLabel:
                      text: &quot;Screen 2&quot;
                      halign: &quot;center&quot;
  
          MDNavigationDrawer:
              id: nav_drawer
  
              ContentNavigationDrawer:
                  screen_manager: screen_manager
                  nav_drawer: nav_drawer
  '''
  
  
  class ContentNavigationDrawer(BoxLayout):
      screen_manager = ObjectProperty()
      nav_drawer = ObjectProperty()
  
  
  
  class App(MDApp):
      def build(self):
          return Builder.load_string(KV)
  
  
  App().run()
  
  </code></pre>
  <p>But when I run the code there's an error. Here's the error;</p>
  <pre><code>Traceback (most recent call last):
     File &quot;c:/Users/DTLM/Desktop/Python/kivy/app.py&quot;, line 113, in &lt;module&gt;
       EduLink().run()
     File &quot;C:\Users\DTLM\AppData\Local\Programs\Python\Python38\lib\site-packages\kivy\app.py&quot;, line 950, in run
       runTouchApp()
     File &quot;C:\Users\DTLM\AppData\Local\Programs\Python\Python38\lib\site-packages\kivy\base.py&quot;, line 573, in runTouchApp
       EventLoop.mainloop()
     File &quot;C:\Users\DTLM\AppData\Local\Programs\Python\Python38\lib\site-packages\kivy\base.py&quot;, line 347, in mainloop
       self.idle()
     File &quot;C:\Users\DTLM\AppData\Local\Programs\Python\Python38\lib\site-packages\kivy\base.py&quot;, line 391, in idle
       self.dispatch_input()
     File &quot;C:\Users\DTLM\AppData\Local\Programs\Python\Python38\lib\site-packages\kivy\base.py&quot;, line 342, in dispatch_input
       post_dispatch_input(*pop(0))
     File &quot;C:\Users\DTLM\AppData\Local\Programs\Python\Python38\lib\site-packages\kivy\base.py&quot;, line 248, in post_dispatch_input
       listener.dispatch('on_motion', etype, me)
     File &quot;kivy\_event.pyx&quot;, line 709, in kivy._event.EventDispatcher.dispatch
     File &quot;C:\Users\DTLM\AppData\Local\Programs\Python\Python38\lib\site-packages\kivy\core\window\__init__.py&quot;, line 1412, in on_motion
       self.dispatch('on_touch_down', me)
     File &quot;kivy\_event.pyx&quot;, line 709, in kivy._event.EventDispatcher.dispatch
     File &quot;C:\Users\DTLM\AppData\Local\Programs\Python\Python38\lib\site-packages\kivy\core\window\__init__.py&quot;, line 1428, in on_touch_down
       if w.dispatch('on_touch_down', touch):
     File &quot;kivy\_event.pyx&quot;, line 709, in kivy._event.EventDispatcher.dispatch
     File &quot;C:\Users\DTLM\AppData\Local\Programs\Python\Python38\lib\site-packages\kivy\uix\relativelayout.py&quot;, line 297, in on_touch_down
       ret = super(RelativeLayout, self).on_touch_down(touch)
     File &quot;C:\Users\DTLM\AppData\Local\Programs\Python\Python38\lib\site-packages\kivy\uix\widget.py&quot;, line 545, in on_touch_down
       if child.dispatch('on_touch_down', touch):
     File &quot;kivy\_event.pyx&quot;, line 709, in kivy._event.EventDispatcher.dispatch
     File &quot;C:\Users\DTLM\AppData\Local\Programs\Python\Python38\lib\site-packages\kivy\uix\widget.py&quot;, line 545, in on_touch_down
       if child.dispatch('on_touch_down', touch):
     File &quot;kivy\_event.pyx&quot;, line 709, in kivy._event.EventDispatcher.dispatch
     File &quot;C:\Users\DTLM\AppData\Local\Programs\Python\Python38\lib\site-packages\kivy\uix\screenmanager.py&quot;, line 1198, in on_touch_down
       return super(ScreenManager, self).on_touch_down(touch)
     File &quot;C:\Users\DTLM\AppData\Local\Programs\Python\Python38\lib\site-packages\kivy\uix\widget.py&quot;, line 545, in on_touch_down
       if child.dispatch('on_touch_down', touch):
     File &quot;kivy\_event.pyx&quot;, line 709, in kivy._event.EventDispatcher.dispatch
     File &quot;C:\Users\DTLM\AppData\Local\Programs\Python\Python38\lib\site-packages\kivy\uix\relativelayout.py&quot;, line 297, in on_touch_down
       ret = super(RelativeLayout, self).on_touch_down(touch)
     File &quot;C:\Users\DTLM\AppData\Local\Programs\Python\Python38\lib\site-packages\kivy\uix\widget.py&quot;, line 545, in on_touch_down
       if child.dispatch('on_touch_down', touch):
     File &quot;kivy\_event.pyx&quot;, line 709, in kivy._event.EventDispatcher.dispatch
     File &quot;C:\Users\DTLM\AppData\Local\Programs\Python\Python38\lib\site-packages\kivy\uix\widget.py&quot;, line 545, in on_touch_down
       if child.dispatch('on_touch_down', touch):
     File &quot;kivy\_event.pyx&quot;, line 709, in kivy._event.EventDispatcher.dispatch
     File &quot;C:\Users\DTLM\AppData\Local\Programs\Python\Python38\lib\site-packages\kivymd\uix\behaviors\ripplebehavior.py&quot;, line 231, in on_touch_down
       return super().on_touch_down(touch)
     File &quot;C:\Users\DTLM\AppData\Local\Programs\Python\Python38\lib\site-packages\kivymd\uix\button.py&quot;, line 961, in on_touch_down
       return super().on_touch_down(touch)
     File &quot;C:\Users\DTLM\AppData\Local\Programs\Python\Python38\lib\site-packages\kivy\uix\behaviors\button.py&quot;, line 151, in on_touch_down
       self.dispatch('on_press')
     File &quot;kivy\_event.pyx&quot;, line 705, in kivy._event.EventDispatcher.dispatch
     File &quot;kivy\_event.pyx&quot;, line 1248, in kivy._event.EventObservers.dispatch
     File &quot;kivy\_event.pyx&quot;, line 1132, in kivy._event.EventObservers._dispatch
     File &quot;C:\Users\DTLM\AppData\Local\Programs\Python\Python38\lib\site-packages\kivy\lang\builder.py&quot;, line 57, in custom_callback
       exec(__kvlang__.co_value, idmap)
     File &quot;&lt;string&gt;&quot;, line 72, in &lt;module&gt;
   NameError: name 'func' is not defined
  </code></pre>
  <p>Please help, thank you.</p>