Python 屏幕仅显示一个空白的紫色屏幕

Python 屏幕仅显示一个空白的紫色屏幕,python,python-3.x,kivy,kivy-language,kivymd,Python,Python 3.x,Kivy,Kivy Language,Kivymd,我正在将代码从kivy转换为kivymd。但它并没有在屏幕上显示任何内容。我找不到问题所在。。。我如何运行它..我正在使用pycharm。 它在kivy代码中运行良好…我查看了一些kivymd的示例,然后对其进行了转换 .py代码 from kivy.lang import Builder from kivymd.app import MDApp from kivy.uix.popup import Popup from kivy.uix.widget import Widget from ki

我正在将代码从kivy转换为kivymd。但它并没有在屏幕上显示任何内容。我找不到问题所在。。。我如何运行它..我正在使用pycharm。 它在kivy代码中运行良好…我查看了一些kivymd的示例,然后对其进行了转换

.py代码

from kivy.lang import Builder
from kivymd.app import MDApp
from kivy.uix.popup import Popup
from kivy.uix.widget import Widget
from kivy.properties import ObjectProperty
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.gridlayout import MDGridLayout
from kivymd.uix.button import MDFlatButton
import sys, time, threading
import pyrebase
from kivymd.uix.screen import MDScreen
from kivy.uix.screenmanager import ScreenManager, Screen
from datetime import datetime, timedelta
import pandas_datareader.data as web
from kivymd.theming import ThemeManager
import pandas as pd
from kivymd.icon_definitions import md_icons
from kivy.utils import get_color_from_hex
import webbrowser
from kivymd.uix.screen import Screen
from kivymd.uix.list import MDList, ThreeLineListItem, ThreeLineAvatarIconListItem, OneLineListItem
from kivymd.uix.list import IconLeftWidget, ImageLeftWidget
from kivy.uix.scrollview import ScrollView
from kivy.uix.button import Button
from kivymd.uix.card import MDCardSwipe
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.gridlayout import GridLayout
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
import re
from kivy.uix.behaviors import FocusBehavior
from kivy.uix.recycleview.layout import LayoutSelectionBehavior
import pandas as pd
from kivy.clock import Clock
from functools import partial
from kivymd.uix.dialog import MDDialog
from kivymd.uix.textfield import MDTextField, MDTextFieldRound
from kivymd.uix.label import MDLabel
from kivymd.toast import toast
from kivy.core.window import Window

Window.size = (300, 500)
username = ''


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


class SelectableLabel(RecycleDataViewBehavior, MDLabel):
    ''' Add selection support to the Label '''

    index = None
    selected = BooleanProperty(False)
    selectable = BooleanProperty(True)

    txt_input = ObjectProperty(None)
    stock_name = ObjectProperty(None)
    stock_symbol = ObjectProperty(None)
    purchase_price = ObjectProperty(None)
    stop_loss = ObjectProperty(None)
    highlight = ListProperty([1, 1, 1, 1])

    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:

            # App.get_running_app().root.widget_1.ids.txt_input1.text = str(rv.data[index].get("text"))
            xx = str(rv.data[index].get("text"))
            if (xx.find('(NSI)') != -1):
                x, y = xx.split(" (NSI)")
                add_sym = '.NS'
            else:
                x, y = xx.split(" (BSE)")
                add_sym = '.BO'
            print(xx)
            print(x)

            App.get_running_app().root.get_screen('body_screen').widget_1.ids.stock_name.text = x
            f = pd.read_csv("Stock Tickers.csv", encoding="ISO-8859-1", engine='python')
            fl = len(f.index)
            file = pd.DataFrame(f, columns=['Symbols', 'Name', 'Exchange'])

            for i in range(fl):
                for index in range(1):
                    columnSeriesObj_sym = file.iloc[:, 0]
                    columnSeriesObj1 = file.iloc[:, 1]
                    columnSeriesObj_ex = file.iloc[:, 2]
                    before_sym, b = columnSeriesObj_sym.values[i].split('.')

                    if columnSeriesObj1.values[i] == App.get_running_app().root.get_screen(
                            'body_screen').widget_1.ids.stock_name.text:
                        App.get_running_app().root.get_screen(
                            'body_screen').widget_1.ids.stock_symbol.text = before_sym + add_sym




class RV(RecycleView):

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


class DropDownWidget(MDBoxLayout):
    txt_input = ObjectProperty(None)
    rv = ObjectProperty(None)

    stock_name = ObjectProperty(None)
    stock_symbol = ObjectProperty(None)
    purchase_price = ObjectProperty(None)
    stop_loss = ObjectProperty(None)

    def back(self):
        self.clear_texts()
        MDApp.get_running_app().root.transition.direction = 'right'
        MDApp.get_running_app().root.current = 'option_screen'

    def clear_texts(self):
        App.get_running_app().root.get_screen('body_screen').widget_1.ids.txt_input.text = ""
        App.get_running_app().root.get_screen('body_screen').widget_1.ids.stock_name.text = ""
        App.get_running_app().root.get_screen('body_screen').widget_1.ids.stock_symbol.text = ""
        App.get_running_app().root.get_screen('body_screen').widget_1.ids.purchase_price.text = ""
        App.get_running_app().root.get_screen('body_screen').widget_1.ids.stop_loss.text = ""

    def btn_input(self):


        if App.get_running_app().root.get_screen('body_screen').widget_1.ids.stock_name.text == '':
            toast('Please Select Stock')
        elif App.get_running_app().root.get_screen('body_screen').widget_1.ids.stock_symbol.text == '':
            toast('Please Select Stock')
        elif App.get_running_app().root.get_screen('body_screen').widget_1.ids.purchase_price.text == '':
            toast('Please Enter Purchase Price')
        elif App.get_running_app().root.get_screen('body_screen').widget_1.ids.stop_loss.text == '':
            toast('Please Enter Stoploss')

        elif float(App.get_running_app().root.get_screen('body_screen').widget_1.ids.stop_loss.text) <= 100:

            print("Stock Name:", App.get_running_app().root.get_screen('body_screen').widget_1.ids.stock_name.text,
                  "Stock Symbol:", App.get_running_app().root.get_screen('body_screen').widget_1.ids.stock_symbol.text)
            print("Purchase Price:",
                  App.get_running_app().root.get_screen('body_screen').widget_1.ids.purchase_price.text,
                  "Stop Loss(%):", App.get_running_app().root.get_screen('body_screen').widget_1.ids.stop_loss.text)

            # write data to csv file

            file_name ="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": App.get_running_app().root.get_screen(
                        'body_screen').widget_1.ids.stock_name.text,
                                            "Stock Symbol": App.get_running_app().root.get_screen(
                                                'body_screen').widget_1.ids.stock_symbol.text,
                                            "Purchase Price": App.get_running_app().root.get_screen(
                                                'body_screen').widget_1.ids.purchase_price.text,
                                            "Stop Loss(%)": App.get_running_app().root.get_screen(
                                                'body_screen').widget_1.ids.stop_loss.text})

            else:
                myFile = open(file_name, 'w+', newline='')
                myData = [["Stock Name", "Stock Symbol", "Purchase Price", "Stop Loss(%)"],
                          [App.get_running_app().root.get_screen('body_screen').widget_1.ids.stock_name.text,
                           App.get_running_app().root.get_screen('body_screen').widget_1.ids.stock_symbol.text,
                           App.get_running_app().root.get_screen('body_screen').widget_1.ids.purchase_price.text,
                           App.get_running_app().root.get_screen('body_screen').widget_1.ids.stop_loss.text]]

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


            self.clear_texts()



        else:
            App.get_running_app().root.get_screen('body_screen').widget_1.ids.stop_loss.text = ''
            toast(text='The Stoloss should be less then 100%')


class MyTextInput(MDTextFieldRound):
    txt_input = ObjectProperty(None)

    flt_list = ObjectProperty()
    word_list = ListProperty()
    stock_name = ObjectProperty(None)
    stock_symbol = ObjectProperty(None)
    purchase_price = ObjectProperty(None)
    stop_loss = ObjectProperty(None)
    # this is the variable storing the number to which the look-up will start
    starting_no = NumericProperty()
    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.parent.parent.ids.rv.data = []
        if len(value) != 0:
            matches = [word for word in self.word_list if word.lower().find(value.lower()) != -1]

            # display the data in the recycleview
            display_data = []

            for i in matches:
                display_data.append({'text': i})
                self.parent.parent.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 = 250

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


class Body1(MDScreen):
    def build(self):

        f = pd.read_csv("Stock Tickers.csv", encoding="ISO-8859-1", engine='python')
        fl = len(f.index)
        file = pd.DataFrame(f, columns=['Symbols', 'Name', 'Exchange'])

        wl = []
        for i in range(fl):
            for index in range(1):
                columnSeriesObj = file.iloc[:, 1]
                self.columnSeriesObj_ex = file.iloc[:, 2]

                wl.append(columnSeriesObj.values[i] + " (" + self.columnSeriesObj_ex.values[i] + ")")

        tp = tuple(wl)

        self.widget_1 = DropDownWidget()

        self.widget_1.ids.txt_input.word_list = wl
        self.widget_1.ids.txt_input.starting_no = 3

        self.add_widget(self.widget_1)

sm = ScreenManager()
sm.add_widget(Body1(name='body_screen1'))
class stockinput1App(MDApp):
    def build(self):
        kv = Builder.load_file("ss.kv")
        return kv

if __name__ == "__main__":
    stockinput1App().run()
ScreenManager:
    Body1:

<Body1>:
    on_enter:root.build()
    name: 'body_screen1'
    canvas.before:
        Color:
            rgba: 155/255, 159/255, 250/255, 1

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


<DropDownWidget>:
    canvas.before:
        Color:
            rgba: 155/255, 159/255, 250/255, 1

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

    cols:1
    id: DropDownWidget

    stock_name: stock_name
    stock_symbol: stock_symbol
    purchase_price: purchase_price
    stop_loss: stop_loss

    txt_input: txt_input
    rv: rv
    orientation:'vertical'
    spacing: '20dp'
    MDToolbar:

        title:'Add Stock'
        type: "top"
        size_hint_y:0.1
        pos_hint: {'top':1.0}
        left_action_items: [["arrow-left", lambda x: root.back()]]
        md_bg_color:152/255,87/255,189/255,1
        elevation:10


    MDBoxLayout:
        spacing:'5dp'
        orientation:'vertical'
        MDCard:

            md_bg_color:155/255, 159/255, 250/255, 1



            pos_hint: {'center_x': .5, 'center_y': .5}

            elevation:0

            orientation:'vertical'
            spacing:'10dp'

            MyTextInput:
                id: txt_input
                hint_text: "Search"
                icon_right: "magnify"
                icon_right_color:1,1,1,1
                pos_hint: {'center_x': .5, 'center_y': .5}
                size_hint:.9,.2
                line_color_normal:184/255,187/255,252/255,1
                normal_color:1,1,1,0


            RV:
                id: rv
                pos_hint: {'center_x': .5, 'center_y': .5}
                size_hint:1,0.6


        MDCard:

            md_bg_color:155/255, 159/255, 250/255, 1
            orientation:'horizontal'
            pos_hint: {'center_x': .5, 'center_y': .5}
            size_hint:.9,.4
            elevation:0



            MDTextField:
                id: stock_name
                hint_text: "Stock Name"

                readonly: True
                multiline:True
                mode:'rectangle'
                required: True

                outline_color:184/255,187/255,252/255,1
                size:.5,.3


        MDCard:
            orientation:'horizontal'
            pos_hint: {'center_x': .5, 'center_y': .5}
            size_hint:.9,.4
            elevation:0
            md_bg_color:155/255, 159/255, 250/255, 1


            MDTextField:
                id: stock_symbol
                hint_text: "Stock Symbol"
                readonly: True
                multiline:False
                mode:'rectangle'
                required: True
                pos_hint: {'center_x': .5, 'center_y': .5}
                line_color_normal:184/255,187/255,252/255,1


        MDCard:
            orientation:'horizontal'
            pos_hint: {'center_x': .5, 'center_y': .5}
            size_hint:.9,.4
            elevation:0
            md_bg_color:155/255, 159/255, 250/255, 1



            MDTextField:
                id: purchase_price
                hint_text: "Purchase Price"
                input_filter: 'float'
                multiline:False
                mode:'rectangle'
                required: True
                line_color_normal:184/255,187/255,252/255,1
                size:.5,.3

        MDCard:
            orientation:'horizontal'
            pos_hint: {'center_x': .5, 'center_y': .5}
            size_hint:.9,.4
            elevation:0
            md_bg_color:155/255, 159/255, 250/255, 1


            MDTextField:
                id: stop_loss
                hint_text: "Stop Loss(%)"
                input_filter: 'float'
                max_text_length: 3
                multiline:False
                mode:'rectangle'
                required: True
                size:.5,.3
                color_mode: 'custom'
                line_color_normal:1,1,1,1



        MDCard:

            pos_hint: {'center_x': .5, 'center_y': .5}
            size_hint:.5,.5
            elevation:0
            md_bg_color:155/255, 159/255, 250/255, 1

            MDRaisedButton:
                text:"Submit"
                pos_hint: {'center_x': .5, 'center_y': .6}
                size_hint:.5,.7
                md_bg_color:40/255, 44/255, 177/255, 1
                elevation:15
                on_press: root.btn_input()





<MyTextInput>:
    id: MyTextInput
    mode:'rectangle'
    readonly: False
    multiline: False

<SelectableLabel>:

    id: SelectableLabel
    multiline: True


    # Draw a background to indicate selection


    canvas:

        Color:
            rgba: (218/255,112/255,214/255,.6) if self.selected else (1, 1, 1, 0.5)
        Rectangle:
            pos: self.pos if self.selected else (0,0)
            size: self.size if self.selected else (0,0)


    halign:'center'





<RV>:

    canvas:
        Color:
            rgba: 1,1,1,1

        Line:
            width: 1.1
            rectangle: self.x , self.y, self.width, self.height



    height: 10
    bar_width: 20
    scroll_type:['bars']
    viewclass: 'SelectableLabel'

    SelectableRecycleBoxLayout:
        cols:1
        row_default_height: 30
        row_force_default:True
        default_size: self.size, dp(20)
        default_size_hint: 1, None
        size_hint_y: None
        height: 300

        multiselect: False
来自kivy.lang导入生成器
从kivymd.app导入MDApp
从kivy.uix.popup导入弹出窗口
从kivy.uix.widget导入widget
从kivy.properties导入ObjectProperty
从kivymd.uix.boxlayout导入MDBoxLayout
从kivymd.uix.gridlayout导入MDGridLayout
从kivymd.uix.button导入MDFlatButton
导入系统、时间、线程
输入基
从kivymd.uix.screen导入MDScreen
从kivy.uix.screenmanager导入screenmanager,屏幕
从datetime导入datetime,timedelta
以web形式导入datareader.data
从kivymd.theming导入管理器
作为pd进口熊猫
从kivymd.icon_定义导入md_图标
从kivy.utils导入从
导入网络浏览器
从kivymd.uix.screen导入屏幕
从kivymd.uix.list导入MDList、ThreeLineListItem、ThreeLineavariconListItem、OneLineListItem
从kivymd.uix.list导入IconLeftWidget,ImageLeftWidget
从kivy.uix.scrollview导入scrollview
从kivy.uix.button导入按钮
从kivymd.uix.card导入MDCardSwipe
从kivy.properties导入ObjectProperty
导入csv
从操作系统导入路径
从kivy.uix.image导入图像
从kivy.app导入应用程序
从kivy.uix.textinput导入textinput
从kivy.lang导入生成器
从kivy.uix.gridlayout导入gridlayout
从kivy.uix.floatlayout导入floatlayout
从kivy.properties导入NumericProperty、ListProperty、BooleanProperty、ObjectProperty、StringProperty
从kivy.uix.recycleview导入recycleview
从kivy.uix.recyclegridlayout导入recyclegridlayout
从kivy.uix.recycleview.views导入RecycleDataViewBehavior
从kivy.uix.label导入标签
进口稀土
从kivy.uix.behaviors导入焦点行为
从kivy.uix.recycleview.layout导入LayoutSelectionBehavior
作为pd进口熊猫
从kivy.clock导入时钟
从functools导入部分
从kivymd.uix.dialog导入MDDialog
从kivymd.uix.textfield导入MDTextField,MDTextFieldRound
从kivymd.uix.label导入MDLabel
从kivymd.toast导入toast
从kivy.core.window导入窗口
Window.size=(300500)
用户名=“”
类SelectableRecycleBoxLayout(焦点行为、布局选择行为、,
回收利用(IDlayout):
“将选择和焦点行为添加到视图中。”
类SelectableLabel(RecycleDataViewBehavior,MDLabel):
''将选择支持添加到标签''
索引=无
selected=布尔属性(False)
可选=布尔属性(真)
txt_输入=对象属性(无)
股票名称=对象属性(无)
stock_symbol=ObjectProperty(无)
购买价格=对象属性(无)
停止损失=对象属性(无)
highlight=ListProperty([1,1,1,1])
def刷新\视图\属性(自身、rv、索引、数据):
''捕获并处理视图更改''
self.index=索引
返回超级(SelectableLabel,self)。刷新\u视图\u属性(
rv、索引、数据)
def on_触控向下(自身,触控):
''在触地时添加选择''
如果是超级(SelectableLabel,self)。打开时触摸下(触摸):
返回真值
如果自碰撞点(*touch.pos)和自选择:
返回self.parent。使用触摸键选择(self.index,touch)
def应用选项(选择了自身、rv、索引):
''响应视图中的项目选择''
self.selected=是否选中
如果选择了以下选项:
#App.get\u running\u App().root.widget\u 1.ids.txt\u input1.text=str(rv.data[index].get(“text”))
xx=str(rv.data[index].get(“text”))
如果(xx.查找('(NSI)!=-1):
x、 y=xx.分割(“(NSI)”)
添加_sym='.NS'
其他:
x、 y=xx.拆分(“(BSE)”)
添加_sym='.BO'
印刷品(xx)
打印(x)
App.get_running_App().root.get_screen('body_screen').widget_1.ids.stock_name.text=x
f=pd.read\u csv(“Stock Tickers.csv”,encoding=“ISO-8859-1”,engine=“python”)
fl=长度(f指数)
file=pd.DataFrame(f,columns=['Symbols','Name','Exchange'])
对于范围内的i(fl):
对于范围(1)中的索引:
columnSeriesObj_sym=file.iloc[:,0]
columnSeriesObj1=file.iloc[:,1]
columnSeriesObj_ex=file.iloc[:,2]
在_sym之前,b=columnSeriesObj _sym.values[i]。拆分('.'))
如果columnSeriesObj1.values[i]==App.get\u running\u App().root.get\u屏幕(
“body_screen”)。小部件_1.ids.stock_name.text:
App.get\u正在运行\u App().root.get\u屏幕(
“body_screen”).widget_1.ids.stock_symbol.text=在_sym+添加_sym之前
RV级(回收利用审查):
定义初始(自我,**kwargs):
超级(RV,自我)。\uuuuu初始值(**kwargs)
类DropDownWidget(MDBoxLayout):
txt_输入=对象属性(无)
rv=对象属性(无)
股票名称=对象属性(无)
stock_symbol=ObjectProperty(无)
购买价格=对象属性(无)
停止损失=对象属性(无)
def返回(自我):
self.clear_text()
MDApp.get_running_app().root.transition.direction='right'
MDApp.get_running_app().root.current='option_screen'
def清除文本(自身):
App.get_running_App().root.get_screen('body_screen')。widget_1.ids.txt_input.text=“”
App.get_running_App().root.get_screen('body_screen').widget_1.ids.stock_name.text=“”
App.get_running_App().root.get_screen('body_screen')。widget_1.ids.stock_symbol.text=“”
App.get_running_App().root.get_screen('body_screen')。widget_1.ids.purchase_price.text=“”
class stockinput1App(MDApp):
    def build(self):
        kv = Builder.load_file("ss.kv")
        kv.get_screen('body_screen1').build()
        return kv
sm = ScreenManager()
sm.add_widget(Body1(name='body_screen1'))