Problem is in LoginForm.log_in() (code below)
I would like in that order:
clear widgets
show MenuWindow widget
connect via SOAP.
Unfortunately I can't. I don't know why but my app first tries to connect to SOAP server and then cleans widget tree and creates new.
main.py:
# coding=utf-8
from kivy.app import App
from kivy.properties import ObjectProperty
from kivy.uix.boxlayout import BoxLayout
from kivy.factory import Factory
from kivy.storage.jsonstore import JsonStore
from suds.client import Client
import sys
import os
import time, threading
class LoginForm(BoxLayout):
login_input = ObjectProperty()
password_input = ObjectProperty()
def log_in(self):
self.clear_widgets()
menu = Factory.MenuWindow()
self.add_widget(menu)
MenuWindow.change_caption(MenuWindow)
def show_settings(self):
self.clear_widgets()
pokaz = Factory.SettingsWindow()
self.add_widget(pokaz)
def set_written_data_ip():
store = JsonStore('anakonda_mobile.json')
if store.exists('Adres'):
print(store.get('Adres'))
if store.get('Adres')['ip'].strip() != '':
return store.get('Adres')['ip']
else:
return ''
def set_written_data_port():
store = JsonStore('anakonda_mobile.json')
if store.exists('Adres'):
if store.get('Adres')['port'].strip() != '':
return store.get('Adres')['port']
else:
return ''
class SettingsWindow(BoxLayout):
ip_value = ObjectProperty(set_written_data_ip())
port_value = ObjectProperty(set_written_data_port())
def show_logging(self):
self.clear_widgets()
self.add_widget(LoginForm())
def save_ip_port(self):
store = JsonStore('anakonda_mobile.json')
store.put('Adres', ip=self.ip_input.text, port=self.port_input.text)
python = sys.executable
os.execl(python, python, *sys.argv)
class MenuWindow(BoxLayout):
def soap_connect(self):
try:
self.a = Client('http://192.168.1.1:7789/ASOAPService?wsdl')
except Exception as g:
return ''
def change_caption(self):
self.soap_connect(self)
return 'SOAP connected'
class MobileApp(App):
pass
if __name__ == '__main__':
MobileApp().run()
mobile.kv
LoginForm:
<LoginForm>:
login_input: _login
password_input: _password
orientation: "vertical"
BoxLayout:
height: "40dp"
size_hint_y: None
Label:
text: 'Login: '
TextInput:
focus: True
multiline: False
id: _login
Label:
text: 'Hasło: '
TextInput:
multiline: False
id: _password
password: True
BoxLayout:
height: "40dp"
size_hint_y: None
Button:
text:'Zaloguj'
on_press: root.log_in()
Button:
text: 'Ustawienia'
on_press: root.show_settings()
BoxLayout:
<SettingsWindow>:
ip_input: _ip
port_input: _port
orientation: 'vertical'
BoxLayout:
height: "40dp"
size_hint_y: None
Label:
text: 'IP: '
TextInput:
focus: True
multiline: False
id: _ip
text: root.ip_value
Label:
text: 'Port: '
TextInput:
multiline: False
id: _port
text: root.port_value
Button:
text: 'Cofnij'
on_press: root.show_logging()
Button:
text: 'Zapisz'
on_press: root.save_ip_port()
<MenuWindow>
orientation: 'vertical'
BoxLayout:
BoxLayout:
height: "40dp"
size_hint_y: None
Label:
id: _napis
text: 'polaczenie'
#text: root.change_caption()
Button:
text: 'Cofnij'
Related
how do i add buttons to my paintScreen class without the on_touch_down/move interfering and making it so that i draw within a BoxLayout canvas and separate the buttons in a different box so that it wont draw over the buttons? This is the current problem i am having. Also if that problem is fixed then would i be able to save that drawing as an img if i use export_to_png
from kivy.app import App
from kivy.graphics.context_instructions import Color
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.label import Label
from kivy.properties import ObjectProperty
from kivy.uix.textinput import TextInput
from kivy.uix.widget import Widget
from kivy.uix.button import Button
from kivy.uix.dropdown import DropDown
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.spinner import Spinner
from kivy.uix.checkbox import CheckBox
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.lang.builder import Builder
from kivy.uix.recycleview import RecycleView
from kivy.uix.scrollview import ScrollView
from kivy.graphics import Line, Rectangle, Ellipse, Triangle
Builder.load_string("""
<firstScreen>
BoxLayout:
orientation: "vertical"
ScrollView:
size: root.size
GridLayout:
orientation: "vertical"
size_hint_y: None
height: self.minimum_height #<<<<<<<<<<<<<<<<<<<<
row_default_height: 90
cols: 2
Label:
text: "Name: "
TextInput:
multiline: False
Label:
text: "Address: "
TextInput:
multiline: False
Label:
text: "Contact: "
TextInput:
multiline: False
Label:
text: "Telephone: "
TextInput:
multiline: False
Label:
text: "Order Number: "
TextInput:
multiline: False
Label:
text: "Transporter's Name: "
TextInput:
multiline: False
Label:
text: "Vehicle Reg. No.: "
TextInput:
multiline: False
Label:
text: "Driver's Name: "
TextInput:
multiline: False
Label:
text:"Hazchem Requirements: "
Spinner:
id: spinner_1
text: "< Select >"
values: root.pick_opt
Spinner:
id: spinner_2
text: "Waste Details"
values: root.pick_classification
GridLayout:
size_hint: 1, None
rows:2
Label:
text: "Non-Hazardous"
Label:
text: "Hazardous"
CheckBox:
on_active: root.chk_tick
CheckBox:
on_active: root.chk_tick
Spinner:
id: spinner_3
text: "Service Details"
values: root.sog
TextInput:
multiline: False
hint_text: "Enter Volume/Weight"
Spinner:
id: spinner_4
text: "Service Details"
values: root.sog
TextInput:
multiline: False
hint_text: "Enter Volume/Weight"
Spinner:
id: spinner_5
text: "Service Details"
values: root.sog
TextInput:
multiline: False
hint_text: "Enter Volume/Weight"
Spinner:
id: spinner_6
text: "Service Details"
values: root.sog
TextInput:
multiline: False
hint_text: "Enter Volume/Weight"
Button:
text: "Next Screen"
size_hint: 1,.1
on_press: root.manager.current = "screen_2"
<secondScreen>
BoxLayout:
orientation: "horizontal"
ScrollView:
size: root.size
GridLayout:
orientation: "vertical"
size_hint_y: None
height: self.minimum_height #<<<<<<<<<<<<<<<<<<<<
row_default_height: 120
cols: 1
BoxLayout:
orientation: 'vertical'
Spinner:
id: spinner_7
text: "details"
width: self.parent.width * 2
values: root.pick_dets
Spinner:
id: spinner_8
text: "details"
values: root.pick_dets
Spinner:
id: spinner_9
text: "details"
values: root.pick_dets
GridLayout:
cols: 2
rows: 3
Label:
text: "Start Time"
Label:
text: "End Time"
TextInput:
multiline: False
TextInput:
multiline: False
GridLayout:
cols: 2
Label:
text: 'Special Instructions/Remarks'
TextInput:
hint_text: 'Enter Remarks'
Button:
id: signature
text: 'Signature'
on_press: root.manager.current = "screen_signature"
BoxLayout:
orientation: 'vertical'
Button:
text: "Previous Screen"
size_hint: 1,.1
on_press: root.manager.current = "screen_1"
Button:
text: "Next Screen"
size_hint: 1,.1
on_press: root.manager.current = "screen_2"
<paintScreen>
""")
class paintScreen(Screen):
# On mouse press how Paint_brush behave
def on_touch_down(self, touch):
color = (1, 1, 1)
with self.canvas:
Color(*color, mode='hsv')
d = 30.
Line(pos=(touch.x - d / 2, touch.y - d / 2), size=(d, d))
touch.ud['line'] = Line(points=(touch.x, touch.y))
# On mouse movement how Paint_brush behave
def on_touch_move(self, touch):
touch.ud['line'].points += [touch.x, touch.y]
pass
class firstScreen(Screen):
def __init__(self, **kwargs):
self.pick_opt = ["yes", "no"]
self.pick_classification = ["Classification (SANAS 10228)", "HR (1,2,3,4 - Minimum Requirements)",
"Emergency Response Guide Reference"]
self.sog = ['Oil', "Effluent", "Sludge", "Other"]
super(firstScreen, self).__init__(**kwargs)
def chk_tick(self, instance, value):
if value:
print("ticked")
else:
print('unticked')
pass
class secondScreen(Screen):
def __init__(self, **kwargs):
self.pick_dets = ["HP Cleaning", "Chemicals", "Soil Treatment",
"Minor Civils & Plumbing", "Effluent Treatment", "Other"]
super(secondScreen, self).__init__(**kwargs)
pass
class MyScreenManager(ScreenManager, RecycleView):
pass
screen_manager: ScreenManager = ScreenManager()
screen_manager.add_widget(firstScreen(name="screen_1"))
screen_manager.add_widget(secondScreen(name="screen_2"))
screen_manager.add_widget(paintScreen(name="screen_signature"))
class Myapp(App):
def build(self):
return screen_manager
def clear_canvas(self, obj):
self.painter.canvas.clear()
if __name__ == "__main__":
Myapp().run()
this is my 1st time posting here and am so amazed how genius people here are.
i have written a python code using kivy and it works perfectly on my computer even on kivy launcher for android, but the problem is that the result on my phone is always ignoring the float numbers and show just the 1s one.
thanks in advance
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen, ScreenManager
from kivy.config import Config
import time
Builder.load_string("""
<Main>:
GridLayout:
cols:2
Button:
text: "Engine Consumption"
on_press: root.manager.current = "test1"
Button:
text: "Apu Consumption"
on_press: root.manager.current = "test2"
<Test1>
GridLayout:
cols: 2
Label:
text: "Flight Hours: "
TextInput:
id: FH
multiline: False
Label:
text: "Flight Minutes:"
TextInput:
id: FM
multiline: False
Label:
text: "Added Quantity:"
TextInput:
id: AQ
multiline: False
Button:
text: "get result"
on_press: root.get_result()
Label:
id: result
Button:
text: "To Main Page"
on_release: root.manager.current = "main"
Button:
text: "Apu Consumption:"
on_release: root.manager.current = "test2"
<Test2>
GridLayout:
cols: 2
Label:
text: "Apu hours In Last Refill: "
TextInput:
id: FH
multiline: False
Label:
text: "Current Apu Hours:"
TextInput:
id: FM
multiline: False
Label:
text: "Added Quantity:"
TextInput:
id: AQ
multiline: False
Button:
text: "get result"
on_press: root.get_result()
Label:
id: result
Button:
text: "To main Page"
on_release: root.manager.current = "main"
Button:
text: "Engine Consumption"
on_release: root.manager.current = "test1"
""")
class Main(Screen):
pass
class Test1(Screen):
def get_result(self):
fh = self.ids.FH.text
fm = self.ids.FM.text
ad = self.ids.AQ.text
result = int(ad) / (int(fh) + int(fm) / 60)
self.ids.result.text = str(result)
self.ids.result.color = 1,0,1,1
class Test2(Screen):
def get_result(self):
fh = self.ids.FH.text
fm = self.ids.FM.text
ad = self.ids.AQ.text
result = int(ad) / (int(fm) - int(fh))
self.ids.result.text = "the result is: " + str(float(result))
class Test(App):
def build(self):
sm = ScreenManager()
sm.add_widget(Main(name = "main"))
sm.add_widget(Test1(name = "test1"))
sm.add_widget(Test2(name = "test2"))
return sm
Config.set("graphics", "height", "150")
if __name__ == "__main__":
Test().run()
on computer result is 0,4444
and on phone 0
I have created a simple login and registration screen using kivy, but the TextInput do not let me type inside of it? This error is occuring on both the LoginScreen and the RegistrationScreen. I tried looking up past questions on here, but i couldn't find anything.
The Python file:
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
class Login_Screen(Screen):
def login(self):
if self.ids.username.text == "root" and\
self.ids.passwrd.text == "123":
print("Direct Entry")
self.manager.current = "Login_Successful"
else:
print("Wrong Password")
self.manager.current = "Login_Failed"
def registration(self):
self.manager.current = "Registration_Screen"
class LoginConfirmationScreen(Screen):
pass
class Registration_Screen(Screen):
def MainScreen(self):
self.manager.current = "Login_Screen"
class Login_Failed(Screen):
def MainScreen(self):
self.manager.current = "Login_Screen"
class RootWidget(ScreenManager):
pass
Builder.load_file("MainApp.kv")
class MainApp(App):
def build(self):
return RootWidget()
if __name__ == "__main__":
MainApp().run()
And the MainApp.kv file:
<RootWidget>:
id: Main
Login_Screen:
id: login
name: "Login_Screen"
Login_Failed:
id: Failed
name: "Login_Failed"
Registration_Screen:
id: register
name: 'Registration_Screen'
<Login_Screen>:
GridLayout:
rows:3
cols:2
Label:
text: "Username:"
font_size: 20
TextInput:
id: username
multiline: False
hint_text: 'Enter your Username'
Label:
text: "Password"
font_size: 20
TextInput:
id: passwrd
multiline: False
hint_text: 'Enter your Password'
password: True
Button:
text: "Register"
on_press: root.registration()
Button:
text: "Sign In"
on_press: root.login()
<Registration_Screen>:
GridLayout:
rows:3
cols:2
Label:
text: 'First Name:'
font_size: 20
TextInput:
id: FirstName
multiline: False
hint_text: 'Enter your First Name'
Label:
text: 'Surname'
font_size: 20
TextInput:
id: Surname
multiline: False
hint_text: 'Enter your Surname'
Button:
text: "Create Account"
on_press: root.MainScreen()
<Login_Failed>:
BoxLayout:
orientation: "vertical"
Label:
text: "Login Failed"
Button:
text: "Try again"
on_press: root.MainScreen()
Thanks for help :)
Remove this:
Builder.load_file("MainApp.kv")
from your py file because you're App instance, ie:
class MainApp(App):
Loads it automatically already.
This is my first Kivy app, surprisingly there wasn't the usual amount of documentation on copy/paste button text with the clipboard which I assume because it is simple, however I get a traceback saying ValueError embedded null character.
I thought that it was because the button produces text of recently hashed text and it still was contained in a byte string, but when decoding it acts if its already decoded and states string doesn't have a decode attribute. I apologize in advance for any "playing" in my code and if the answer has been staring at me
kivy clipboard doc:
https://kivy.org/docs/api-kivy.core.clipboard.html#
** Update
I believe I found the issue, regardless of the data type that is passed to the clipboard function there is a Value error, I took a look at the kivy file for the clipboard "clipboard_winctypes.py" and under the put() function the function msvcrt.wcscpy_s() is called. When this is commented out the clipboard will copy the button text however, I receive weird things like ⫐ᵄƅ
also under the put() function where text is set to text += u'x00', if this is commented out and msvcrt.wscpy_s() is left uncommented to be called it executes without error but nothing is copied to the clipboard however msvcrt is an object of ctypes.cdll.msvcrt and I don't where to go from here
clipboard_winctypes.py:
'''
Clipboard windows: an implementation of the Clipboard using ctypes.
'''
__all__ = ('ClipboardWindows', )
from kivy.utils import platform
from kivy.core.clipboard import ClipboardBase
if platform != 'win':
raise SystemError('unsupported platform for Windows clipboard')
import ctypes
from ctypes import wintypes
user32 = ctypes.windll.user32
kernel32 = ctypes.windll.kernel32
msvcrt = ctypes.cdll.msvcrt
c_char_p = ctypes.c_char_p
c_wchar_p = ctypes.c_wchar_p
class ClipboardWindows(ClipboardBase):
def get(self, mimetype='text/plain'):
GetClipboardData = user32.GetClipboardData
GetClipboardData.argtypes = [wintypes.UINT]
GetClipboardData.restype = wintypes.HANDLE
user32.OpenClipboard(user32.GetActiveWindow())
# 1 is CF_TEXT
pcontents = GetClipboardData(13)
if not pcontents:
return ''
data = c_wchar_p(pcontents).value.encode(self._encoding)
user32.CloseClipboard()
return data
def put(self, text, mimetype='text/plain'):
text = text.decode(self._encoding) # auto converted later
text += u'\x00'
SetClipboardData = user32.SetClipboardData
SetClipboardData.argtypes = [wintypes.UINT, wintypes.HANDLE]
SetClipboardData.restype = wintypes.HANDLE
GlobalAlloc = kernel32.GlobalAlloc
GlobalAlloc.argtypes = [wintypes.UINT, ctypes.c_size_t]
GlobalAlloc.restype = wintypes.HGLOBAL
CF_UNICODETEXT = 13
user32.OpenClipboard(user32.GetActiveWindow())
user32.EmptyClipboard()
hCd = GlobalAlloc(0, len(text) * ctypes.sizeof(ctypes.c_wchar))
msvcrt.wcscpy_s(c_wchar_p(hCd), len(text), c_wchar_p(text))
SetClipboardData(CF_UNICODETEXT, hCd)
user32.CloseClipboard()
def get_types(self):
return ['text/plain']
cry_hash.py
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.togglebutton import ToggleButton
from kivy.uix.label import Label
import hashlib
class Hasher:
def __init__(self, to_hash, hash_alg, hash_length):
if to_hash != type(bytes):
self.to_hash = bytes(to_hash, encoding='utf-8')
else:
self.to_hash = to_hash
self.hash_alg = hash_alg
self.hash_length = int(hash_length)
def create_hash(self):
hash_object = hashlib.new(self.hash_alg)
hash_object.update(self.to_hash)
result = hash_object.hexdigest()[:self.hash_length]
del hash_object
return result
class LabelBackground(Label):
pass
class CryHashWidgetBoxLayout(BoxLayout):
def get_hash(self, user_hash, hash_length):
tb = next((t for t in ToggleButton.get_widgets('hash_type') if t.state == 'down'), None)
hash_alg = tb.text if tb else None
krypt_tool = Hasher(user_hash, hash_alg, hash_length)
hashed_input = krypt_tool.create_hash()
self.ids.hash_return.text = hashed_input
def reset(self, text_reset):
incoming = text_reset
del incoming
incoming = ''
self.ids.hash_return.text = incoming
class CryHashApp(App):
def build(self):
return CryHashWidgetBoxLayout()
if __name__ == '__main__':
CryHashApp().run()
KV file: cryhash.kv
#File name: cry_hash.py
#:import utils kivy.utils
#:import Clipboard kivy.core.clipboard.Clipboard
<ToggleButton>:
background_color: utils.get_color_from_hex('#E00000')
<TextInput>:
background_color: utils.get_color_from_hex('#5F9B9F')
<Label>
font_name: 'fonts/arialbd.ttf'
<CryHashWidgetBoxLayout>:
orientation: 'vertical'
Label:
font_name: 'fonts/welga.ttf'
color: utils.get_color_from_hex('#E00000')
text: 'Welcome to Cry Hash!'
font_size: 80
Button:
id: hash_return
background_color: utils.get_color_from_hex('#F15E92')
font_size: 40
text: ''
on_release:
Clipboard.copy(hash_return.text)
BoxLayout:
orientation: 'horizontal'
BoxLayout:
orientation: 'vertical'
Label:
id: bg_hash
color: utils.get_color_from_hex('#E00000')
text: 'Enter text to hash'
TextInput:
id: user_hash
multiline: False
text: ''
Label:
id: bg_length
color: utils.get_color_from_hex('#E00000')
text: 'Enter length'
TextInput:
id: get_hash_length
multiline: False
text: '10'
Button:
id: get_data
background_color: utils.get_color_from_hex('#1900FF')
text: 'get hash!'
on_release: root.get_hash(user_hash.text, get_hash_length.text)
BoxLayout:
orientation: 'vertical'
ToggleButton:
id: SHA256
text: 'SHA256'
state: 'down'
group: 'hash_type'
ToggleButton:
id: SHA512
text: 'SHA512'
group: 'hash_type'
ToggleButton:
id: SHA1
text: 'SHA1'
group: 'hash_type'
ToggleButton:
id: MD5
text: 'MD5'
group: 'hash_type'
To summarize other answers:
Issue:
"ValueError: embedded null character" when using copy to clipboard (Kivy)
Solution:
pip install pyperclip
pyperclip.copy('text that you want into clipboard')
I have found a work around, I believe that is just simply a bug in the Kivy framework, if someone can find a true solution in the kivy code please let me know, otherwise I simply imported pyperclip, created a pyperclip copy function in the .py file and called to the function in the .kv file. Works flawlessly!
cry_hash.py:
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.togglebutton import ToggleButton
from kivy.uix.label import Label
import hashlib
import pyperclip
class Hasher:
def __init__(self, to_hash, hash_alg, hash_length):
if to_hash != type(bytes):
self.to_hash = bytes(to_hash, encoding='utf-8')
else:
self.to_hash = to_hash
self.hash_alg = hash_alg
self.hash_length = int(hash_length)
def create_hash(self):
hash_object = hashlib.new(self.hash_alg)
hash_object.update(self.to_hash)
result = hash_object.hexdigest()[:self.hash_length]
del hash_object
return result
class LabelBackground(Label):
pass
class CryHashWidgetBoxLayout(BoxLayout):
def get_hash(self, user_hash, hash_length):
tb = next((t for t in ToggleButton.get_widgets('hash_type') if t.state == 'down'), None)
hash_alg = tb.text if tb else None
krypt_tool = Hasher(user_hash, hash_alg, hash_length)
hashed_input = krypt_tool.create_hash()
self.ids.hash_return.text = str(hashed_input)
def reset(self, text_reset):
incoming = text_reset
del incoming
incoming = ''
self.ids.hash_return.text = incoming
def copy_text(self, text):
pyperclip.copy(text)
class CryHashApp(App):
def build(self):
return CryHashWidgetBoxLayout()
if __name__ == '__main__':
CryHashApp().run()
cryhash.kv:
#File name: cry_hash.py
#:import utils kivy.utils
#:import Clipboard kivy.core.clipboard.Clipboard
<ToggleButton>:
background_color: utils.get_color_from_hex('#E00000')
<TextInput>:
background_color: utils.get_color_from_hex('#5F9B9F')
<Label>
font_name: 'fonts/arialbd.ttf'
<CryHashWidgetBoxLayout>:
orientation: 'vertical'
Label:
font_name: 'fonts/welga.ttf'
color: utils.get_color_from_hex('#E00000')
text: 'Welcome to Cry Hash!'
font_size: 80
Button:
id: hash_return
background_color: utils.get_color_from_hex('#F15E92')
font_size: 40
text: ''
on_release: root.copy_text(hash_return.text)
BoxLayout:
orientation: 'horizontal'
BoxLayout:
orientation: 'vertical'
Label:
id: bg_hash
color: utils.get_color_from_hex('#E00000')
text: 'Enter text to hash'
TextInput:
id: user_hash
multiline: False
text: ''
Label:
id: bg_length
color: utils.get_color_from_hex('#E00000')
text: 'Enter length'
TextInput:
id: get_hash_length
multiline: False
text: '10'
Button:
id: get_data
background_color: utils.get_color_from_hex('#1900FF')
text: 'get hash!'
on_release: root.get_hash(user_hash.text, get_hash_length.text)
BoxLayout:
orientation: 'vertical'
ToggleButton:
id: SHA256
text: 'SHA256'
state: 'down'
group: 'hash_type'
ToggleButton:
id: SHA512
text: 'SHA512'
group: 'hash_type'
ToggleButton:
id: SHA1
text: 'SHA1'
group: 'hash_type'
ToggleButton:
id: MD5
text: 'MD5'
group: 'hash_type'
The whole code is working well. But when u go to:
student > Add New student > > Fill all columns of new student > then submit
it's not working and I can't figure out the issue. Here is the following code. Any help will be appreciated
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen ,FadeTransition
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
import csv
from kivy.uix.textinput import TextInput
Builder.load_string("""
<MenuScreen>:
BoxLayout:
Button:
text: 'Teacher'
on_press: root.manager.current = 'screen1'
Button:
text: 'Student '
on_press:root.manager.current = 'screen2'
Button:
text: 'Quit'
<Screen1>:
BoxLayout:
Button:
text: 'Teacher Info'
#on_press:root.manager.current = 'login'
Button:
text: 'Teacher Attandance'
Button:
text: 'Add New Teacher'
on_press:root.manager.current = 'add_teacher'
Button:
text: 'Back'
on_press:root.manager.current ='menu'
<add_new_teacher>:
GridLayout:
cols:2
Label:
text:'Name'
TextInput:
id: name_input
multiline: False
Label:
text:'Father Name'
TextInput:
id: name_input
multiline: False
Label:
text: 'Mother Name'
TextInput:
id: name_input
multiline: False
Label:
text: 'Class'
TextInput:
id: name_input
multine: False
Label:
text:'Roll no.'
text: 'Student Info'
on_press:root.csv_std()
Button:
text: 'Student Attandance'
# on_press:root.manager.current ='login'
Button:
text: 'Add New Student'
on_press:root.manager.current = 'add_student'
Button
text: 'Back'
on_press:root.manager.current = 'menu'
<add_new_student>:
GridLayout:
cols:2
Label:
text:'Name'
TextInput:
id: self.name
multiline: False
Label:
text:'Father Name'
TextInput:
id: self.fname
multiline: False
Label:
text: 'Mother Name'
TextInput:
id: self.mname
multiline: False
Label:
text: 'Class'
TextInput:
id: self.c
multine: False
Label:
text:'Roll no.'
TextInput:
id: self.r
multiline:False
Button:
text:'Print'
Button:
text:'Submit'
on_press:root.print_text()
Button:
text:'Back'
on_press:root.manager.current= 'screen2'
""")
# Declare both screens
class MenuScreen(Screen):
pass
class add_new_teacher(Screen):
pass
class Screen1(Screen):
pass
class Screen2(Screen):
def csv_std(self):
f = open("a.csv", 'r')
reader = csv.reader(f)
for row in reader:
print(" ".join(row))
pass
class add_new_student(Screen):
def print_text(self):
for child in reversed(self.children):
if isinstance(child, TextInput):
print child.text
pass
# Create the screen manager
sm = ScreenManager()
sm.add_widget(MenuScreen(name='menu'))
sm.add_widget(add_new_teacher(name='add_teacher'))
sm.add_widget(add_new_student(name='add_student'))
sm.add_widget(Screen1(name='screen1'))
sm.add_widget(Screen2(name='screen2'))
class TestApp(App):
def build(self):
return sm
if __name__ == '__main__':
TestApp().run()
You code formatting was horrible, but at least you didn't use backticks. For future cases, copy&paste your whole example you want to show here, then select that example(whole) and press Ctrl + K, which will indent all selected lines, so that it'd look ok.
The code works exactly how it supposed to work, because root.print_text() targets add_new_student class and its children - not GridLayout which you want to access.
Edit the line with for to this: for child in reversed(self.children[0].children): and you are good to go. :)
Or more efficient solution would be to get that Screen to behave as a layout too, which you can get with inheritting both from Screen and some layout, but ensure the layout is first:
class add_new_student(GridLayout, Screen):
def print_text(self):
for child in reversed(self.children):
if isinstance(child, TextInput):
print child.text
kv:
<add_new_student>:
cols:2
Label:
text:'Name'