changing/updating app with mouse click - kivy -


i'm working on mobile app first time kivy. i've made progress , have "main" page shows before else. user press button , page change little more useful.

at moment giant button , when click on nothing happens...

i'm new kivy , awesome.

i've tried comment code "think" happening.

from kivy.uix.widget import widget kivy.uix.boxlayout import boxlayout kivy.uix.gridlayout import gridlayout kivy.uix.carousel import carousel kivy.uix.label import label kivy.uix.button import button kivy.graphics import color kivy.app import app 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 show big button 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 layout thinking can         #not sure need change make 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 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 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 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 miles driven on 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 makes numofcarous carousels         #and puts '.' @ placeholder         check = false         layout = boxlayout(orientation='horizontal')         in range(0,numofcarous):             if == (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)             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         n in range(0,placeholder-1):             factor=factor*10.0         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() 

thanks again everyone!!!!

the fifth line of showdata method layout = gridlayout(cols=1,rows=4,spacing=[2,0]). overrides variable 'layout' passed function - python forgets first layout variable existed , knows new gridlayout created. after gets added new layout fine don't tell kivy it.

if delete line, new layouts added root layout want, , visible homescreen updated show them.

so...that should fix general problem, general structure seems bit non-ideal. why not make new class, class homegrid(gridlayout):, give class methods want alter showdata. way don't have keep track of class variables , pass them around, you're associating object transformation object itself.

i recommend reading kivy language, make of layout design easy. can make basic templates widgets there easily, rather messing around stuff b.bind becomes unwieldy once you're binding many functions.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -