Answers for "kivy button on press call function"

2

kivy button on press call function

app.py:

import kivy
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.button import Button

class Launch(BoxLayout):
    def __init__(self, **kwargs):
        super(Launch, self).__init__(**kwargs)

    def say_hello(self): #<---- function that the button is calling
        print "hello"


class App(App):
    def build(self):
        return Launch()


if __name__ == '__main__':
    App().run()
    
app.kv:

#:kivy 1.9.1

<Launch>:
    BoxLayout:
        Button:
            size:(80,80)
            size_hint:(None,None)
            text:"Click me"
            on_press: say_hello() #<--- calls the say_hello() function
Posted by: Guest on June-18-2020
0

kivy button on press call function

import kivy
from kivy.uix.widget import Widget
from kivy.lang import Builder
from kivymd.app import MDApp

Builder.load_file('foo.kv')

class layout1(Widget):
  pass
class App(MDApp):
  def build(self):
    self.theme_cls.theme_style = "Dark"
    self.theme_cls.primary_palette = "BlueGray" 
    return layout1()
  def themeSwitch(self):# function that will be called from layout1() class
    pass


#kv file from here on.
<layout1>
	BoxLayout:
		Button:
          size_hint:(None,None)  
          size:(80,80)
          text:"Click me"
          on_press: app.themeSwitch()
Posted by: Guest on April-17-2021
0

kivy button on press call function

button.bind(self.function)
Posted by: Guest on October-02-2021

Code answers related to "kivy button on press call function"

Python Answers by Framework

Browse Popular Code Answers by Language