This is one of those questions I've looked everywhere for the answer and can't find it anywhere.
I can't access ids at all. I've printed the screen and the screen shows the ids I need but when I try to pull the ids I get key error ex ids['delete'] or no attribute ex. ids.delete
I've looked everywhere on stack overflow and other sites even looked into the kivy/kivymd docs but I still can't find the answer
It looks exactly like what others do to get the ids
I'm using Pydroid
#pylint:disable=E1101
from __future__ import print_function
import os.path
from kivy.lang.builder import Builder
from kivymd.app import MDApp
from kivymd.uix.label import MDLabel
from kivymd.uix.screen import Screen
from kivymd.uix.screenmanager import ScreenManager
from kivymd.uix.button import MDRectangleFlatButton
from kivymd.uix.textfield import MDTextField
from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
SCOPES = ['https://mail.google.com/']
creds = None
# The file token.json stores the user's access and refresh tokens, and is
# created automatically when the authorization flow completes for the first
# time.
if os.path.exists('token.json'):
creds = Credentials.from_authorized_user_file('token.json', SCOPES)
# If there are no (valid) credentials available, let the user log in.
if not creds or not creds.valid:
if creds and creds.expired and creds.refresh_token:
creds.refresh(Request())
else:
flow = InstalledAppFlow.from_client_secrets_file(
'credentials.json', SCOPES)
creds = flow.run_local_server(port=0)
# Save the credentials for the next run
with open('token.json', 'w') as token:
token.write(creds.to_json())
emailTextField = ''
class Screen1(Screen):
def __init__(self, **kwargs):
super().__init__(**kwargs)
kv = """
ScreenManager:
id: scrn_mnger
name: scrn_mnger
Screen1:
<Screen1>:
id: main_scrn
name: 'main_scrn'
MDTextField:
id:'emails_to_delete'
hint_text:'Enter Emails'
icon_left:'email'
size_hint: None, None
pos_hint:{'center_x':0.5, 'center_y':0.8}
mode:'rectangle'
width:800
MDRectangleFlatButton:
id: 'delete'
name: 'delete'
text: 'Delete'
pos_hint: {'center_x':0.5, 'center_y':.7}
on_release: app.on_start()
"""
class Manager(MDApp):
def build(self):
self.screen = Builder.load_string(kv)
return self.screen
def on_start(self):
#This code bit here is the issue
print(self.root.get_screen('main_scrn').ids.delete)
#This code bit here is the issue
try:
service = build('gmail', 'v1', credentials=creds)
messages = service.users().messages().list(userId='me', q='from:')
if messages:
messagesList = messages
else:
messagesList = []
messageIDs = []
for i in messagesList:
messageIDs.append(i['id'])
service.users().messages().batchDelete(userId='me', body={'ids':messageIDs}).execute()
except HttpError as err:
print(err)
def main():
pass
if __name__ == '__main__':
Manager().run()
Error
[INFO ] [Logger ] Record log in /storage/emulated/0/Documents/GoogleAPI/.kivy/logs/kivy_22-10-05_2.txt
[INFO ] [Kivy ] v2.0.0
[INFO ] [Kivy ] Installed at "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/site-packages/kivy/__init__.py"
[INFO ] [Python ] v3.9.7 (default, Oct 6 2021, 01:34:26)
[GCC 11.1.0]
[INFO ] [Python ] Interpreter at "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/bin/python3"
[INFO ] [Factory ] 186 symbols loaded
[INFO ] [KivyMD ] 1.0.2, git-38fe356, 2022-08-11 (installed at "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/site-packages/kivymd/__init__.py")
[INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2, img_pil (img_ffpyplayer ignored)
[INFO ] [Text ] Provider: sdl2
[INFO ] [Window ] Provider: sdl2
[INFO ] [GL ] Using the "OpenGL ES 2" graphics system
[INFO ] [GL ] Backend used <sdl2>
[INFO ] [GL ] OpenGL version <b'OpenGL ES 3.2 V@0502.0 (GIT@3c44ec2e9d, I9dd863ea0e, 1602076608) (Date:10/07/20)'>
[INFO ] [GL ] OpenGL vendor <b'Qualcomm'>
[INFO ] [GL ] OpenGL renderer <b'Adreno (TM) 619'>
[INFO ] [GL ] OpenGL parsed version: 3, 2
[INFO ] [GL ] Texture max size <16384>
[INFO ] [GL ] Texture max units <16>
[INFO ] [Window ] auto add sdl2 input provider
[INFO ] [Window ] virtual keyboard not allowed, single mode, not docked
[INFO ] [GL ] NPOT texture support is available
Traceback (most recent call last):
File "kivy/properties.pyx", line 861, in kivy.properties.ObservableDict.__getattr__
KeyError: 'delete'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/storage/emulated/0/Documents/GoogleAPI/quickstart.py", line 138, in <module>
Manager().run()
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/site-packages/kivy/app.py", line 949, in run
self._run_prepare()
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/site-packages/kivy/app.py", line 944, in _run_prepare
self.dispatch('on_start')
File "kivy/_event.pyx", line 709, in kivy._event.EventDispatcher.dispatch
File "/storage/emulated/0/Documents/GoogleAPI/quickstart.py", line 99, in on_start
print(self.root.get_screen('main_scrn').ids.delete)
File "kivy/properties.pyx", line 864, in kivy.properties.ObservableDict.__getattr__
AttributeError: 'super' object has no attribute '__getattr__'