Kivy buttons not pressable

204
May 30, 2017, at 08:53 AM

I dynamically created buttons based on how many sound files there are in a folder but I'm having an issue where I cannot press any of the buttons. I tried looking up tutorial or similar question but it seems as what I have should be correct, yet when I run it I get a window with buttons, but the buttons do nothing when pressed.

import os, glob
from os.path import isfile, join
from os import listdir
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.config import Config
from kivy.app import App
Config.set('graphics', 'borderless', False)
Config.set('graphics', 'width', '500')
Config.set('graphics', 'height', '300')
class Soundboard(GridLayout):
def soundSearch(self):
    os.chdir("./sound")
    self.sounds = []
    for Wav in glob.glob("*.wav"):
        self.sounds.append(Wav)
    for Flac in glob.glob("*.flac"):
        self.sounds.append(Flac)
    for mp3 in glob.glob("*.mp3"):
        self.sounds.append(mp3)
def __init__(self,**kwargs):
    super(Soundboard, self).__init__(**kwargs)
    self.soundSearch()
    self.cols = 3
    for sound in self.sounds:
        self.button = Button(text=os.path.splitext(sound)[0])
        self.button.bind(on_press=lambda x:self.clk())
        self.add_widget(self.button)
    self.row_force_default = True
    self.row_default_height = 40
    self.padding = [50, 10]
    self.spacing = 5
def clk(self, *args):
    print('The button is pushed')
class MyApp(App):
    def build(self):
        return Soundboard()
if __name__ == '__main__':
    MyApp().run()
Answer 1

In the code you provided there is a problem with indentation. Other than that, the code works fine for me:

import glob
import os
from kivy.app import App
from kivy.config import Config
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
Config.set('graphics', 'borderless', False)
Config.set('graphics', 'width', '500')
Config.set('graphics', 'height', '300')
class Soundboard(GridLayout):
    def soundSearch(self):
        self.sounds = []
        os.chdir("./sound")
        for Wav in glob.glob("*.wav"):
            self.sounds.append(Wav)
        for Flac in glob.glob("*.flac"):
            self.sounds.append(Flac)
        for mp3 in glob.glob("*.mp3"):
            self.sounds.append(mp3)
    def __init__(self,**kwargs):
        super(Soundboard, self).__init__(**kwargs)
        self.soundSearch()
        self.cols = 3
        for sound in self.sounds:
            self.button = Button(text=os.path.splitext(sound)[0])
            self.button.bind(on_press=lambda x: self.clk())
            self.add_widget(self.button)
        self.row_force_default = True
        self.row_default_height = 40
        self.padding = [50, 10]
        self.spacing = 5
    def clk(self, *args):
        print('The button is pushed')
class MyApp(App):
    def build(self):
        return Soundboard()
if __name__ == '__main__':
    MyApp().run()

READ ALSO
Speeding up an .exe created with Pyinstaller

Speeding up an .exe created with Pyinstaller

I've converted my program (written in Python 36

227
linking to a js file from django

linking to a js file from django

I am trying use the <script src=""> tag to link to EasyAutocompleteI am using django, and can't seem to figure out how to load it

310
Incorrect SQL generated by SQLAlchemy

Incorrect SQL generated by SQLAlchemy

I have a function that returns a query that would fetch ┬źNew priorities for emails┬╗ by given account idFirst it selects a domain name for that account, and then selects a data structure for it

301