python - Name is not defined when using variables and functions in Kivy -


i'm creating program interacts server, program employees use on mobile device, i'm using kivy, , i'm doing gui first. followed instructions on documentation best of understanding, cannot seem solve problem. code refers variables , functions, but, whenever runs crashes , gives me , error code stating name of variable or function (whichever called first) not defined

here's code:

import sqlalchemy import os import kivy import datetime kivy.uix.screenmanager import screenmanager, screen kivy import app kivy.uix import button kivy.uix.textinput import textinput kivy.uix.label import label kivy.lang import builder  admincode = "..." # sql functions # incomplete of # shift pulled database shift = false  def userlogin(id = 'unfilled', password = 'unfilled'):     global user     global localhost_enabled     if id == "localtest" , password == admincode:         user = id         localhost_enabled = true         return true     elif id == "servertest" , password == admincode:         user = id         localhost_enabled = false         return true def userlogout():     user = ''  def shiftin():     global shift     shift = true def shiftout():     global shift     shift = false def submitform(startcash=0, endcash=0):     netcash = endcash - startcash     print("netcash = {0}".format(netcash)) def shiftgetter():     if shift == true:         return "shift out"     else:         return "shift in" # kivy building  builder.load_string(""" <loginscreen>:     boxlayout:         label:             text: 'id:'         textinput:             id: logininputuser             text: ''             multiline: false         label:             text: "password:"         textinput:             id: logininputpassword             text: ''             password: true             multiline: false         button:             text: 'login'             on_press:                 if userlogin(logininputuser.text, logininputpassword.text): loginvalidationtext.text = ''                 if userlogin(logininputuser.text, logininputpassword.text): root.manager.current = 'home'                 else: loginvalidationtext.text = 'invalid username or password'         label:             text: ''             id: 'loginvalidationtext'   <homescreen>:     boxlayout:         button:             text: 'logout'             on_press:                 userlogout()                 root.manager.current = 'login'         button:             text: 'open submission form'             on_press: root.manager.current = 'form'         button:             text: 'shift out' if shift == true else 'shift in'             on_press:                 if shift: shiftout()                 else: shiftin()   <formscreen>:     boxlayout:         button:             text: 'back menu'             on_press: root.manager.current = 'home'         label:             text: 'start money:'         textinput:             id: startcash             text: ''             multiline: false         label:             text: 'end money:'         textinput:             id: endcash             text: ''             multiline: false         button:             text: 'submit'             on_press: submitform(startcash = int(startcash.text), endcash = int(endcash.text))  """) class loginscreen(screen):     pass  class homescreen(screen):     pass  class formscreen(screen):     pass  sm = screenmanager() sm.add_widget(loginscreen(name='login')) sm.add_widget(homescreen(name='home')) sm.add_widget(formscreen(name='form')) class realapp(app):     def build(self):         return sm  realapp().run() 

and error message:

[info   ] [logger      ] record log in c:\users\sherl\.kivy\logs\kivy_17-08-20_28.txt [info   ] [kivy        ] v1.10.0 [info   ] [python      ] v3.6.2 (v3.6.2:5fd33b5, jul  8 2017, 04:14:34) [msc v.1900 32 bit (intel)] [info   ] [factory     ] 194 symbols loaded [info   ] [image       ] providers: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored) [info   ] [text        ] provider: sdl2 [info   ] [osc         ] using <thread> socket [info   ] [window      ] provider: sdl2 [info   ] [gl          ] using "opengl" graphics system [info   ] [gl          ] glew initialization succeeded [info   ] [gl          ] backend used <glew> [info   ] [gl          ] opengl version <b'4.4.0 - build 20.19.15.4531'> [info   ] [gl          ] opengl vendor <b'intel'> [info   ] [gl          ] opengl renderer <b'intel(r) hd graphics 5500'> [info   ] [gl          ] opengl parsed version: 4, 4 [info   ] [gl          ] shading version <b'4.40 - build 20.19.15.4531'> [info   ] [gl          ] texture max size <16384> [info   ] [gl          ] texture max units <32> [info   ] [shader      ] fragment shader: <b"warning: 0:7: '' :  #version directive missing"> [info   ] [shader      ] vertex shader: <b"warning: 0:7: '' :  #version directive missing"> [info   ] [window      ] auto add sdl2 input provider [info   ] [window      ] virtual keyboard not allowed, single mode, not docked  traceback (most recent call last):    file "c:\users\sherl\appdata\local\programs\python\python36-32\lib\site-packages\kivy\lang\builder.py", line 249, in create_handler      return eval(value, idmap), bound_list    file "<string>", line 39, in <module>  nameerror: name 'shift' not defined   during handling of above exception, exception occurred:   traceback (most recent call last):    file "c:\users\sherl\appdata\local\programs\python\python36-32\lib\site-packages\kivy\lang\builder.py", line 597, in _apply_rule      rctx['ids'])    file "c:\users\sherl\appdata\local\programs\python\python36-32\lib\site-packages\kivy\lang\builder.py", line 254, in create_handler      cause=tb)  kivy.lang.builder.builderexception: parser: file "<inline>", line 39:  ...       37:            on_press: root.manager.current = 'form'       38:        button:  >>   39:            text: 'shift out' if shift == true else 'shift in'       40:            on_press:       41:                if shift: shiftout()  ...  nameerror: name 'shift' not defined    file "c:\users\sherl\appdata\local\programs\python\python36-32\lib\site-packages\kivy\lang\builder.py", line 249, in create_handler      return eval(value, idmap), bound_list    file "<string>", line 39, in <module>    during handling of above exception, exception occurred:   traceback (most recent call last):    file "c:\users\sherl\pycharmprojects\pokerroomsql\user\userdepreciated.py", line 126, in <module>      sm.add_widget(homescreen(name='home'))    file "c:\users\sherl\appdata\local\programs\python\python36-32\lib\site-packages\kivy\uix\relativelayout.py", line 265, in __init__      super(relativelayout, self).__init__(**kw)    file "c:\users\sherl\appdata\local\programs\python\python36-32\lib\site-packages\kivy\uix\floatlayout.py", line 65, in __init__      super(floatlayout, self).__init__(**kwargs)    file "c:\users\sherl\appdata\local\programs\python\python36-32\lib\site-packages\kivy\uix\layout.py", line 76, in __init__      super(layout, self).__init__(**kwargs)    file "c:\users\sherl\appdata\local\programs\python\python36-32\lib\site-packages\kivy\uix\widget.py", line 345, in __init__      builder.apply(self, ignored_consts=self._kwargs_applied_init)    file "c:\users\sherl\appdata\local\programs\python\python36-32\lib\site-packages\kivy\lang\builder.py", line 451, in apply      self._apply_rule(widget, rule, rule, ignored_consts=ignored_consts)    file "c:\users\sherl\appdata\local\programs\python\python36-32\lib\site-packages\kivy\lang\builder.py", line 612, in _apply_rule      e), cause=tb)  kivy.lang.builder.builderexception: parser: file "<inline>", line 39:  ...       37:            on_press: root.manager.current = 'form'       38:        button:  >>   39:            text: 'shift out' if shift == true else 'shift in'       40:            on_press:       41:                if shift: shiftout()  ...  builderexception: parser: file "<inline>", line 39:  ...       37:            on_press: root.manager.current = 'form'       38:        button:  >>   39:            text: 'shift out' if shift == true else 'shift in'       40:            on_press:       41:                if shift: shiftout()  ...  nameerror: name 'shift' not defined    file "c:\users\sherl\appdata\local\programs\python\python36-32\lib\site-packages\kivy\lang\builder.py", line 249, in create_handler      return eval(value, idmap), bound_list    file "<string>", line 39, in <module>     file "c:\users\sherl\appdata\local\programs\python\python36-32\lib\site-packages\kivy\lang\builder.py", line 597, in _apply_rule      rctx['ids'])    file "c:\users\sherl\appdata\local\programs\python\python36-32\lib\site-packages\kivy\lang\builder.py", line 254, in create_handler      cause=tb) 

you have following errors:

  1. change "from kivy import app" "from kivy.app import app"
  2. add "from kivy.properties import booleanproperty"
  3. replace "shift = false" "shift = booleanproperty(false)"
  4. remove references "global shift"

i have separated program python program , kv file shown below.

modifed main.py

import sqlalchemy import os import datetime  kivy.app import app kivy.properties import booleanproperty kivy.uix.screenmanager import screenmanager, screen  admincode = "..." # sql functions # incomplete of # shift pulled database shift = booleanproperty(false)   def userlogin(id='unfilled', password='unfilled'):     global user     global localhost_enabled     if id == "localtest" , password == admincode:         user = id         localhost_enabled = true         return true     elif id == "servertest" , password == admincode:         user = id         localhost_enabled = false         return true   def userlogout():     user = ''   def shiftin():     shift = true   def shiftout():     shift = false   def submitform(startcash=0, endcash=0):     netcash = endcash - startcash     print("netcash = {0}".format(netcash))   def shiftgetter():     if shift:         return "shift out"     else:         return "shift in"   class loginscreen(screen):     pass   class homescreen(screen):     pass   class formscreen(screen):     pass   sm = screenmanager() sm.add_widget(loginscreen(name='login')) sm.add_widget(homescreen(name='home')) sm.add_widget(formscreen(name='form'))   class realapp(app):     def build(self):         return sm  if __name__ == '__main__':     realapp().run() 

real.kv

#:kivy 1.10.0  <loginscreen>:     boxlayout:         label:             text: 'id:'         textinput:             id: logininputuser             text: ''             multiline: false         label:             text: "password:"         textinput:             id: logininputpassword             text: ''             password: true             multiline: false         button:             text: 'login'             on_press:                 if userlogin(logininputuser.text, logininputpassword.text): loginvalidationtext.text = ''                 if userlogin(logininputuser.text, logininputpassword.text): root.manager.current = 'home'                 else: loginvalidationtext.text = 'invalid username or password'         label:             text: ''             id: 'loginvalidationtext'   <homescreen>:     boxlayout:         button:             text: 'logout'             on_press:                 userlogout()                 root.manager.current = 'login'         button:             text: 'open submission form'             on_press: root.manager.current = 'form'         button:             text: 'shift out' if shift == true else 'shift in'             on_press:                 if shift: shiftout()                 else: shiftin()   <formscreen>:     boxlayout:         button:             text: 'back menu'             on_press: root.manager.current = 'home'         label:             text: 'start money:'         textinput:             id: startcash             text: ''             multiline: false         label:             text: 'end money:'         textinput:             id: endcash             text: ''             multiline: false         button:             text: 'submit'             on_press: submitform(startcash = int(startcash.text), endcash = int(endcash.text)) 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -