I checked other answered questions for this error, however, I could not manage to solve the particular problem I am having. Therefore I wanted ask it here:
Hope you are all doing well.
I am trying to create a simple Kivy GUI, where I will be displaying live data variables. As an authentication, I wanted to create a Login screen, however, I could not manage to make it work. Here is my code below:
import mysql.connector
from mysql.connector import Error
from kivy.lang import Builder
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.clock import Clock
from kivy.uix.button import Button
from kivy.uix.textinput import TextInput
Builder.load_string("""
<LVAD_GUIDemo>:
name: "login_page"
BoxLayout:
TextInput:
id: username
TextInput:
id: password
password: True # hide password
Button:
text: "Giriş Yap"
on_release: root.verify_credentials()
""")
class LVAD_GUIDemo:
def __init__(self, **kwargs):
super(LVAD_GUIDemo, self).__init__(**kwargs)
self.anchor_x = 'right'
self.anchor_y = 'top'
self.cols = 1
def build(self):
global username, password
username = TextInput(text="Kullanıcı Adı:", width=6, height=3)
password = TextInput(text="Şifre:", width=6, height=3)
username.size_hint = (1,0.06)
self.add_widget(username)
password.size_hint = (1,0.06)
self.add_widget(password)
touchBarbtn1 = Button(text='Giriş Yap', size_hint_y=0.05,size_hint_x=1)
touchBarbtn1.bind(on_press=lambda x: self.deneme)
self.add_widget(touchBarbtn1)
self.update_view()
def deneme(self):
print("ehe")
def verifyCred(self):
if self.ids["username"].text == "kaan" and self.ids["password"].text == "kaan1999":
self.manager.current = "user"
class LVAD_GUIDemoApp(App):
def build(self):
return LVAD_GUIDemo()
if __name__ == '__main__':
LVAD_GUIDemoApp().run()
When I run the code above, I receive the following error:
[CRITICAL] App.root must be an instance of Widget ..... raise Exception('Invalid instance in App.root') Exception: Invalid instance in App.root
What is the cause of this? I looked up for the post which contains the same error, however, most of those caused by returning a class object, instead of a widget. However, I made sure that I am returning a widget by adding paranthesis.
CodePudding user response:
Your class LVAD_GUIDemo
is not a Widget
. It should extend some Widget
class.