本文介绍了如何在另一个textinput中获取选定的文本.得到错误"ScreenManager"对象没有属性"widget_1"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将选定的文本从recycleview获取到txt_input1,但它抛出错误.它在单独的.py文件中工作,但是随后我将代码转移到了run1.py文件中,并且它不起作用,新代码是start和end,并在注释"#Start"中添加了该代码.和结束"

I am trying to get the selected text from recycleview to the txt_input1 but it is throwing error. It was working in the separate .py file but then I transfered the code into my run1.py file and its not working the new code is start and end is enclosed in comments "#Start" and "end"

run1.py文件

from kivy.lang import Builder
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty
from Option import OptionApp
import sys, time, threading
from kivy.uix.screenmanager import ScreenManager, Screen
from datetime import datetime
import pandas_datareader.data as web
import pandas as pd
from kivymd.uix.screen import Screen
from kivymd.uix.list import MDList,ThreeLineListItem,ThreeLineAvatarIconListItem
from kivymd.uix.list import IconLeftWidget,ImageLeftWidget
from kivy.uix.scrollview import ScrollView
from kivy.uix.button import Button
from kivymd.app import MDApp
from kivy.app import App
from kivy.properties import ObjectProperty
import csv
from os import path
from kivy.uix.image import Image
from kivy.app import App
from kivy.uix.textinput import TextInput
from kivy.lang import Builder
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from kivy.properties import NumericProperty, ListProperty, BooleanProperty, ObjectProperty, StringProperty
from kivy.uix.recycleview import RecycleView
from kivy.uix.recyclegridlayout import RecycleGridLayout
from kivy.uix.recycleview.views import RecycleDataViewBehavior
from kivy.uix.label import Label
from kivy.uix.recycleboxlayout import RecycleBoxLayout
from kivy.uix.behaviors import FocusBehavior
from kivy.uix.recycleview.layout import LayoutSelectionBehavior
import pandas as pd

kv = Builder.load_file("run1.kv")



#Start
class SelectableRecycleBoxLayout(FocusBehavior, LayoutSelectionBehavior,
                                 RecycleBoxLayout):
    ''' Adds selection and focus behaviour to the view. '''


class SelectableLabel(RecycleDataViewBehavior, Label):
    ''' Add selection support to the Label '''
    index = None
    selected = BooleanProperty(False)
    selectable = BooleanProperty(True)
    txt_input1 = ObjectProperty(None)
    txt_input = ObjectProperty(None)

    def refresh_view_attrs(self, rv, index, data):
        ''' Catch and handle the view changes '''
        self.index = index
        return super(SelectableLabel, self).refresh_view_attrs(
            rv, index, data)

    def on_touch_down(self, touch):
        ''' Add selection on touch down '''
        if super(SelectableLabel, self).on_touch_down(touch):
            return True
        if self.collide_point(*touch.pos) and self.selectable:
            return self.parent.select_with_touch(self.index, touch)

    def apply_selection(self, rv, index, is_selected):

        ''' Respond to the selection of items in the view. '''

        self.selected = is_selected
        if is_selected:

            # self.root.ids.txt_input1.text = str(rv.data[index].get("text"))
            App.get_running_app().root.widget_1.ids.txt_input1.text = str(rv.data[index].get("text"))

class RV(RecycleView):
    def __init__(self, **kwargs):
        super(RV, self).__init__(**kwargs)


class DropDownWidget(BoxLayout):
    txt_input = ObjectProperty()
    rv = ObjectProperty()
    txt_input1 = ObjectProperty()


class MyTextInput(TextInput):
    txt_input = ObjectProperty()
    txt_input1 = ObjectProperty(None)
    flt_list = ObjectProperty()
    word_list = ListProperty()
    # this is the variable storing the number to which the look-up will start
    starting_no = NumericProperty(3)
    suggestion_text = ''

    def __init__(self, **kwargs):
        super(MyTextInput, self).__init__(**kwargs)

    def on_text(self, instance, value):
        # find all the occurrence of the word
        self.parent.ids.rv.data = []
        matches = [self.word_list[i] for i in range(len(self.word_list)) if
                   self.word_list[i][:self.starting_no] == value[:self.starting_no]]
        # display the data in the recycleview
        display_data = []
        for i in matches:
            display_data.append({'text': i})
        self.parent.ids.rv.data = display_data
        # ensure the size is okay
        if len(matches) <= 10:
            self.parent.height = (50 + (len(matches) * 20))
        else:
            self.parent.height = 240

    def keyboard_on_key_down(self, window, keycode, text, modifiers):
        if self.suggestion_text and keycode[1] == 'tab':
            self.insert_text(self.suggestion_text + ' ')
            return True
        return super(MyTextInput, self).keyboard_on_key_down(window, keycode, text, modifiers)


class Body(Screen):
    def __init__(self, **kwargs):

        super(Body, self).__init__(**kwargs)
        f = pd.read_csv("stoploss.csv")
        fl = len(f.index)
        file = pd.DataFrame(f, columns=['Stock Symbol', 'Purchase Price', 'Stock Name', 'Stop Loss(%)'])
        j = 0
        wl = []
        for i in range(fl):
            for index in range(1):
                columnSeriesObj = file.iloc[:, 2]
                # pp = iter(columnSeriesObj.values)
                # pp1 = next(pp)
                # print(pp1)

                wl.append(columnSeriesObj.values[i])

        tp = tuple(wl)
        print(str(tp))


        self.widget_1 = DropDownWidget(pos_hint={'center_x': .5, 'center_y': .5},
                                       size_hint=(None, None), size=(600, 60))
        self.widget_1.ids.txt_input.word_list = wl
        self.widget_1.ids.txt_input.starting_no = 3

        self.add_widget(self.widget_1)
    #End





class signin(Screen):

    user_name = ObjectProperty(None)

    def btn(self):

        username = self.user_name.text
        print(username)
        sm.current = 'option_screen'

class option(Screen):

    def btn_addstock(self):
        sm.current = 'body_screen'

    def btn_stoplosslist(self):
        sm.canvas.clear()
        sm.current = 'Stoploss_ip'







class stockinput(Screen):
    stock_name = ObjectProperty(None)
    stock_symbol = ObjectProperty(None)
    purchase_price = ObjectProperty(None)
    stop_loss = ObjectProperty(None)


    def btn(self):
        end = datetime.today().date()
        start = end.year - 10
        start = datetime(start, datetime.today().month, datetime.today().day).date()
        uname = input("Enter user name: ")
        print("Stock Name:", self.stock_name.text, "Stock Symbol:", self.stock_symbol.text)
        print("Purchase Price:",self.purchase_price.text,"Stop Loss(%):",self.stop_loss.text)

        #write data to csv file

        # if path.exists("stoploss.csv"):
        #     myFile = open('stoploss.csv', 'a')
        # else:
        #     myFile = open('stoploss.csv', 'w')
        file_name = stockinput.uname + "_stoploss.csv"
        if path.exists(file_name):
            with open(file_name, "a+", newline='')as newFile :
                fieldnames = ["Stock Name", "Stock Symbol", "Purchase Price", "Stop Loss(%)"]
                newFileWriter = csv.DictWriter(newFile, fieldnames=fieldnames)
                newFileWriter.writerow({"Stock Name" : self.stock_name.text,"Stock Symbol" : self.stock_symbol.text,"Purchase Price" : self.purchase_price.text,"Stop Loss(%)" : self.stop_loss.text})

        else:
            myFile = open(file_name, 'w+')
            myData = [["Stock Name", "Stock Symbol", "Purchase Price", "Stop Loss(%)"],[self.stock_name.text, self.stock_symbol.text, self.purchase_price.text, self.stop_loss.text]]

            with myFile:
                writer = csv.writer(myFile)
                writer.writerows(myData)

        df = web.DataReader(self.stock_symbol.text, 'yahoo', start, end,)
        print(df.tail())

        self.stock_name.text = ""
        self.stock_symbol.text = ""
        self.purchase_price.text = ""
        self.stop_loss.text = ""

f = pd.read_csv("stoploss.csv")
file = pd.DataFrame(f, columns=['Stock Symbol','Purchase Price','Stock Name','Stop Loss(%)'])


class img(Screen):
    def build(self,**kwargs):
        super(img, self).__init__(**kwargs)
        screen = self
        image = Image(source='please_wait.gif')
        screen.add_widget(image)

class ListApp(Screen):

    # def imgpr(self,**kwargs):
    #     super(ListApp, self).__init__(**kwargs)
    #
    #         time.sleep(0.1)

    # t = threading.Thread(target=imgpr)
    # t.start()
    def build(self,**kwargs):
        super(ListApp, self).__init__(**kwargs)
        flag = True


        screen = self
        # if flag:
        #
        #
        #     sm.add_widget(ListApp(name='Stoploss_ip'))


        end = datetime(2020, 12, 14)
        start = datetime(2020, 12, 14)

        btn = Button(text="Back",
                     font_size="20sp",

                     background_color=(255/255, 229/255, 204/255, 1),
                     color=(1, 1, 1, 1),
                     size=(12, 12),
                     size_hint=(.1, .05),
                     pos=(600, 500))
        btn.bind(on_press=lambda *args: setattr(sm, 'current', "option_screen"))

        scroll = ScrollView()
        list_view = MDList()


        scroll.add_widget(list_view)



        i = 0
        fl = len(file.index)
        try:
            for index in range(fl):

                for index in range(1):
                    columnSeriesObj2 = file.iloc[:, 0]

                    df = web.DataReader(columnSeriesObj2.values[i],'yahoo', start, end,retry_count=3)
                    print(df.head())
                    Objname = file.iloc[:, 2]
                    columnSeriesObj = df.iloc[:, 3]
                    columnSeriesObj1 = file.iloc[:, 1]
                    ObjStoploss = file.iloc[:, 3]

                    cp = iter(columnSeriesObj.values)
                    pp = iter(columnSeriesObj1.values)
                    pp1 = next(pp)
                    cp1 = columnSeriesObj.values[0]


                    sl = columnSeriesObj1.values[i] - (columnSeriesObj1.values[i] * (ObjStoploss.values[i]/100))


                    if cp1 <= sl:
                        image = ImageLeftWidget(source='loss.png')
                        items = ThreeLineAvatarIconListItem(text="Alert sale " + Objname.values[i], secondary_text='Close price: '+str(cp1),
                                                            tertiary_text='Stoploss: ' + str(sl))
                        items.add_widget(image)
                        list_view.add_widget(items)



                        i=i+1


                    else:
                        image = ImageLeftWidget(source='profit.jpg')
                        items = ThreeLineAvatarIconListItem(text="Chill " + Objname.values[i],
                                                            secondary_text='Close price: ' + str(cp1),
                                                            tertiary_text='Stoploss: ' + str(sl))
                        items.add_widget(image)
                        list_view.add_widget(items)


                        i=i+1
        except ConnectionAbortedError:
            print("Check your Internet connection")
        except ConnectionRefusedError:
            print("Check your Internet connection")
        except ConnectionError:
            print("Check your Internet connection")
        except ConnectionResetError:
            print("Check your Internet connection")
        except TimeoutError:
            print("Timeout!!!!...Check your Internet connection")
        except KeyError:
            pass

        except:
            print("Something went wrong")
        print("Done")

        # flag = False
        # if flag ==False:
        screen.add_widget(scroll)
        screen.add_widget(btn)
        # return screen


class WindowsManager(ScreenManager):
    pass

sm = ScreenManager()
sm.add_widget(signin(name='signin_screen'))
sm.add_widget(option(name='option_screen'))
sm.add_widget(stockinput(name='stockinput_screen'))
sm.add_widget(img(name='image_screen'))
sm.add_widget(ListApp(name='Stoploss_ip'))
sm.add_widget(Body(name='body_screen'))

class run1(MDApp):
    def build(self):
        return sm

if __name__ == "__main__":
    run1().run()

run1.kv文件

<WindowsManager>:
    signin:
    option:
    stockinput:
    ListApp:
    Body:


<Body>:
    name: 'body_screen'
    canvas.before:
        Color:
            rgba: 188/255, 143/255, 145/255, 1

        Rectangle:
            pos: self.pos
            size: self.size


<DropDownWidget>:
    id: DropDownWidget
    canvas:
        Color:
            rgba:(1, 1, 1, 1)
        Rectangle:
            # pos: self.pos
            size: self.size

    # orientation: 'vertical'
    spacing: 20
    txt_input: txt_input
    rv: rv

    txt_input1: txt_input1
    MyTextInput:
        id: txt_input1
        pos: 400,300
        size_hint_y: None
        height: 50
    MyTextInput:
        id: txt_input
        hint_text:'Enter here'
        size_hint_y: None
        height: 50
    RV:
        id: rv




<MyTextInput>:
    id: MyTextInput

    readonly: False
    multiline: False

<SelectableLabel>:

    id: SelectableLabel

    # Draw a background to indicate selection
    color: 0,0,0,1
    canvas.before:
        Color:
            rgba: (0, 0, 1, .5) if self.selected else (1, 1, 1, 1)
        Rectangle:
            # pos: self.pos
            size: self.size

<RV>:


    canvas:
        Color:
            rgba: 0,0,0,.2

        Line:
            rectangle: self.x +1 , self.y, self.width - 2, self.height -2


    bar_width: 10
    scroll_type:['bars']
    viewclass: 'SelectableLabel'
    SelectableRecycleBoxLayout:
        default_size: None, dp(20)
        default_size_hint: 1, None
        size_hint_y: None
        height: self.minimum_height
        orientation: 'vertical'
        multiselect: False
<signin>:

    canvas.before:
        Color:
            rgba: 164/255, 66/255, 220/255, 1
        Rectangle:
            pos: self.pos
            size: self.size

    name: 'signin_screen'

    user_name: user_name



    GridLayout:
        pos_hint: {'center_x': .75, 'center_y': .15}
        row_force_default : True
        row_default_height : 50
        col_force_default : True
        col_default_width : 400
        spacing: '15dp'
        cols: 1

        TextInput:
            id: user_name
            multiline:False
            size_hint: 5.0 ,.1

            hint_text: "Email_ID"

        Button:
            text:"Submit"
            font_size: 20
            color:0,0,0,1

            size_hint: .5 ,.3
            background_normal: ''
            background_color: (255/255, 153/255, 71/255, 1)
            on_press : root.btn()





        Label:
            text:"Please Do not change the Email_ID. Data will be saved as per your Email_ID"
            pos: 180,80

<option>:
    canvas.before:
        Color:
            rgba: 138/255, 104/255, 175/255, 1
        Rectangle:
            pos: self.pos
            size: self.size
    name: 'option_screen'

    GridLayout:
        pos_hint: {'center_x': .83, 'center_y': .18}
        row_force_default : True
        row_default_height : 100
        col_force_default : True
        col_default_width : 250
        spacing: '20dp'


        cols:1

        Button:
            text:"Add Stock"
            color:0,0,0,1
            font_size: 18
            size_hint: .1 ,.1
            pos: 150,150
            background_normal: ''
            background_color: (204/255, 0, 204/255, 1)

            on_press : root.manager.current = 'body_screen'

        Button:
            text:"Check Stoploss"
            color:0,0,0,1
            font_size: 18
            size_hint: .1 ,.1
            pos: 250,120
            background_normal: ''
            background_color:(127/255, 193/255, 184/255, 1)


            on_press : root.manager.current = 'Stoploss_ip'




<stockinput>:
    canvas.before:
        Color:
            rgba: 188/255, 143/255, 145/255, 1

        Rectangle:
            pos: self.pos
            size: self.size
    name: 'stockinput_screen'
    stock_name: stock_name
    stock_symbol: stock_symbol
    purchase_price: purchase_price
    stop_loss: stop_loss

    GridLayout:

        pos_hint: {'center_x': .67, 'center_y': .2}
        row_force_default : True
        row_default_height : 40
        col_force_default : True
        col_default_width : 250
        spacing: '10dp'
        cols:2



#            pos_hint: {'center_x': .53, 'center_y': .12}
#            row_force_default : True
#            row_default_height : 30
#            col_force_default : True
#            col_default_width : 250
#            spacing: '20dp'

        Label:
            text: "Stock Name: "

        TextInput:
            id: stock_name
            multiline:False

        Label:
            text: "Stock Symbol: "

        TextInput:
            id: stock_symbol
            multiline:False

        Label:
            text: "Purchase Price: "

        TextInput:
            id: purchase_price
            multiline:False

        Label:
            text: "Stop Loss(%): "

        TextInput:
            id: stop_loss
            multiline:False

        Button:
            text:"Submit"
            color:102/255, 204/255, 0, 1
            font_size:18
            background_color: (204/255, 0, 102/255, 1)
            on_press: root.btn()
        Button:
            text:"Back"
            color:0,0,0,1
            font_size:18
            background_normal: ''
            background_color: (204/255, 102/255, 0, 1)
            on_press: root.manager.current = 'option_screen'

<img>:
    name: 'image_screen'
    on_enter:root.build()

<ListApp>:

    name: 'Stoploss_ip'

    on_enter:root.build()

我遇到以下错误

"C:\Users\Rushi Dada\AppData\Local\Programs\Python\Python37\python.exe" D:/FirebaseLoginScreen-master/run1.py
[INFO   ] [Logger      ] Record log in C:\Users\Rushi Dada\.kivy\logs\kivy_20-12-14_87.txt
[INFO   ] [deps        ] Successfully imported "kivy_deps.gstreamer" 0.3.1
[INFO   ] [deps        ] Successfully imported "kivy_deps.angle" 0.1.10
[INFO   ] [deps        ] Successfully imported "kivy_deps.glew" 0.1.12
[INFO   ] [deps        ] Successfully imported "kivy_deps.sdl2" 0.1.23
[INFO   ] [Kivy        ] v1.11.1
[INFO   ] [Kivy        ] Installed at "C:\Users\Rushi Dada\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\__init__.py"
[INFO   ] [Python      ] v3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC v.1916 64 bit (AMD64)]
[INFO   ] [Python      ] Interpreter at "C:\Users\Rushi Dada\AppData\Local\Programs\Python\Python37\python.exe"
[INFO   ] [Factory     ] 184 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil, img_gif (img_ffpyplayer ignored)
[INFO   ] [KivyMD      ] v0.104.1
[INFO   ] [Window      ] Provider: sdl2
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[INFO   ] [GL          ] GLEW initialization succeeded
[INFO   ] [GL          ] Backend used <glew>
[INFO   ] [GL          ] OpenGL version <b'4.6.0 NVIDIA 391.35'>
[INFO   ] [GL          ] OpenGL vendor <b'NVIDIA Corporation'>
[INFO   ] [GL          ] OpenGL renderer <b'GeForce GT 635M/PCIe/SSE2'>
[INFO   ] [GL          ] OpenGL parsed version: 4, 6
[INFO   ] [GL          ] Shading version <b'4.60 NVIDIA'>
[INFO   ] [GL          ] Texture max size <16384>
[INFO   ] [GL          ] Texture max units <32>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO   ] [Text        ] Provider: sdl2
[INFO   ] [GL          ] NPOT texture support is available
('Tesla inc', 'Tata Motors Limited ', 'asv', 'tesla', 'ploul', 'fd', 's', 'asdsd', 'trtdfsddfdfd', 'abc')
[WARNING] [Lang        ] The file D:\FirebaseLoginScreen-master\run1.kv is loaded multiples times, you might have unwanted behaviors.
[INFO   ] [Base        ] Start application main loop

[INFO   ] [Base        ] Leaving application in progress...
 Traceback (most recent call last):
   File "D:/FirebaseLoginScreen-master/run1.py", line 481, in <module>
     run1().run()
   File "C:\Users\Rushi Dada\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\app.py", line 855, in run
     runTouchApp()
   File "C:\Users\Rushi Dada\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\base.py", line 504, in runTouchApp
     EventLoop.window.mainloop()
   File "C:\Users\Rushi Dada\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\core\window\window_sdl2.py", line 747, in mainloop
     self._mainloop()
   File "C:\Users\Rushi Dada\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\core\window\window_sdl2.py", line 479, in _mainloop
     EventLoop.idle()
   File "C:\Users\Rushi Dada\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\base.py", line 342, in idle
     self.dispatch_input()
   File "C:\Users\Rushi Dada\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\base.py", line 327, in dispatch_input
     post_dispatch_input(*pop(0))
   File "C:\Users\Rushi Dada\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\base.py", line 233, in post_dispatch_input
     listener.dispatch('on_motion', etype, me)
   File "kivy\_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
   File "C:\Users\Rushi Dada\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\core\window\__init__.py", line 1402, in on_motion
     self.dispatch('on_touch_down', me)
   File "kivy\_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
   File "C:\Users\Rushi Dada\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\core\window\__init__.py", line 1418, in on_touch_down
     if w.dispatch('on_touch_down', touch):
   File "kivy\_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
   File "C:\Users\Rushi Dada\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\uix\screenmanager.py", line 1191, in on_touch_down
     return super(ScreenManager, self).on_touch_down(touch)
   File "C:\Users\Rushi Dada\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\uix\widget.py", line 549, in on_touch_down
     if child.dispatch('on_touch_down', touch):
   File "kivy\_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
   File "C:\Users\Rushi Dada\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\uix\relativelayout.py", line 288, in on_touch_down
     ret = super(RelativeLayout, self).on_touch_down(touch)
   File "C:\Users\Rushi Dada\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\uix\widget.py", line 549, in on_touch_down
     if child.dispatch('on_touch_down', touch):
   File "kivy\_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
   File "C:\Users\Rushi Dada\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\uix\widget.py", line 549, in on_touch_down
     if child.dispatch('on_touch_down', touch):
   File "kivy\_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
   File "C:\Users\Rushi Dada\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\uix\scrollview.py", line 647, in on_touch_down
     if self.dispatch('on_scroll_start', touch):
   File "kivy\_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
   File "C:\Users\Rushi Dada\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\uix\scrollview.py", line 736, in on_scroll_start
     return self.simulate_touch_down(touch)
   File "C:\Users\Rushi Dada\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\uix\scrollview.py", line 642, in simulate_touch_down
     ret = super(ScrollView, self).on_touch_down(touch)
   File "C:\Users\Rushi Dada\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\uix\widget.py", line 549, in on_touch_down
     if child.dispatch('on_touch_down', touch):
   File "kivy\_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
   File "C:\Users\Rushi Dada\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\uix\behaviors\focus.py", line 443, in on_touch_down
     return super(FocusBehavior, self).on_touch_down(touch)
   File "C:\Users\Rushi Dada\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\uix\widget.py", line 549, in on_touch_down
     if child.dispatch('on_touch_down', touch):
   File "kivy\_event.pyx", line 707, in kivy._event.EventDispatcher.dispatch
   File "D:/FirebaseLoginScreen-master/run1.py", line 145, in on_touch_down
     return self.parent.select_with_touch(self.index, touch)
   File "C:\Users\Rushi Dada\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\uix\behaviors\compoundselection.py", line 345, in select_with_touch
     self.select_node(node)
   File "C:\Users\Rushi Dada\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\uix\recycleview\layout.py", line 103, in select_node
     self.apply_selection(node, view, True)
   File "C:\Users\Rushi Dada\AppData\Local\Programs\Python\Python37\lib\site-packages\kivy\uix\recycleview\layout.py", line 143, in apply_selection
     view.apply_selection(self.recycleview, index, is_selected)
   File "D:/FirebaseLoginScreen-master/run1.py", line 155, in apply_selection
     App.get_running_app().root.widget_1.ids.txt_input1.text = str(rv.data[index].get("text"))
 AttributeError: 'ScreenManager' object has no attribute 'widget_1'

Process finished with exit code 1

推荐答案

您已经从上一个问题更改了App的结构.您的应用程序现在使用ScreenManager.因此,访问TextInput的代码必须更改为相应的值:

You have changed the structure of your App from your previous question. Your App now uses a ScreenManager. So the code accessing the TextInput must change to account for that:

        App.get_running_app().root.get_screen('body_screen').widget_1.ids.txt_input1.text = str(rv.data[index].get("text"))

这篇关于如何在另一个textinput中获取选定的文本.得到错误"ScreenManager"对象没有属性"widget_1"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 16:00