Note that there are some explanatory texts on larger screens.

plurals
  1. POchanging/updating app with mouse click - kivy
    text
    copied!<p>I'm working on a mobile app for the first time with Kivy. I've made some progress and I would like to have a "Main" page that shows up before anything else. The user would then press a button and the page would change to something a little more useful.</p> <p>At the moment I get a giant button and when I click on it nothing happens...</p> <p>I'm new to kivy and any help would be awesome.</p> <p>I've tried to comment my code with what I "think" is happening.</p> <pre class="lang-py prettyprint-override"><code>from kivy.uix.widget import Widget from kivy.uix.boxlayout import BoxLayout from kivy.uix.gridlayout import GridLayout from kivy.uix.carousel import Carousel from kivy.uix.label import Label from kivy.uix.button import Button from kivy.graphics import Color from kivy.app import App from kivy.graphics.instructions import CanvasBase CAROUSEL_OUTPUT = [0,1,2,3,4,5,6,7,8,9] class MyApp(App): def build(self): #for starters just show a big button that will call #showData when clicked. b = Button(text='Click Me!!!') self.layout = GridLayout(cols=1,rows=4,spacing=[2,0]) self.layout.add_widget(b) #i pass the layout thinking that i can it #not sure what i need to change to make it work b.bind(on_press=(lambda e=1:self.showData(self.layout))) return self.layout def showData(self,layout): self.Money = [] self.Trip = [] self.Gals = [] #set up the local layout layout = GridLayout(cols=1,rows=4,spacing=[2,0]) row1 = BoxLayout(orientation='vertical') row2 = BoxLayout(orientation='vertical') row3 = BoxLayout(orientation='vertical') w = self.makeCarousels(6,4,1) l = Label(text='Please enter the total amount paid.') row1.add_widget(l) row1.add_widget(w) layout.add_widget(row1) w = self.makeCarousels(7,3,2) l = Label(text='Please enter the total amount of gallons of gasoline purchased.') row2.add_widget(l) row2.add_widget(w) layout.add_widget(row2) w = self.makeCarousels(5,4,3) b = Button(text='Click Me!!!') b.bind(on_press=(lambda e=1: self.printCindexes())) l = Label(text='Please enter the miles driven on your last tank.(Trip)') row3.add_widget(l) row3.add_widget(w) layout.add_widget(row3) layout.add_widget(b) self.layout = layout return layout def makeCarousels(self,numOfCarous,placeHolder,row): #this function just makes numOfCarous carousels #and puts a '.' at placeHolder check = False layout = BoxLayout(orientation='horizontal') for i in range(0,numOfCarous): if i == (placeHolder - 1): check = True c = Carousel(direction = 'top') else: c = Carousel(direction = 'top') if row == 1: self.Money.append(c) elif row == 2: self.Gals.append(c) elif row == 3: self.Trip.append(c) for num in CAROUSEL_OUTPUT: l = Label(text=str(num)) c.add_widget(l) if check: l = Label(text='.') layout.add_widget(c) layout.add_widget(l) check = False else: layout.add_widget(c) return layout def printCindexes(self): self.calculateValues(self.Money,4,1) self.calculateValues(self.Gals,3,2) self.calculateValues(self.Trip,4,3) print '\n' def calculateValues(self,list,placeHolder,row): numOfEntries = len(list) total = 0.0 factor = 1.0 for n in range(0,placeHolder-1): factor=factor*10.0 for n in list: total += factor*n.index factor = factor/10.0 if row == 1: print 'Total Paid: $%6.2f' %(total) elif row == 2: print 'Total Gallons: %7.4f gallons' %(total) elif row == 3: print 'Total Trip: %5.1f miles' %(total) if __name__ == '__main__': MyApp().run() </code></pre> <p>Thanks again everyone!!!!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload