【发布时间】:2021-05-29 22:05:04
【问题描述】:
我一直在搞乱 python kivy,我偶然发现了标题中给出的错误。我正在尝试通过 kivy 使用 yfinance 包来打印任意股票的股价。我得到错误:AttributeError:'TextInput'对象没有属性'replace'。你们有没有人知道我在这里做错了什么:
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.core.window import Window
from kivy.properties import ObjectProperty
from kivy.properties import StringProperty
from kivy.uix.widget import Widget
from kivy.config import Config
import yfinance as yf
import numpy as np
class MyStock(FloatLayout):
enterticker = ObjectProperty(None)
enterstartdate = ObjectProperty(None)
enterenddate = ObjectProperty(None)
def DownloadStockData(self, ticker, starting, ending):
Download = yf.download(ticker, start = starting, end = ending)
StockData1 = Download["Close"]
StockValue = [0]*len(StockData1)
for i in range(len(StockValue)):
StockValue[i] = StockData1[i]
return StockValue
def btn(self):
self.stockvalue.text = self.DownloadStockData(self.enterticker, self.enterstartdate, self.enterenddate)
print(self.enterticker.text, self.enterstartdate.text, self.enterenddate.text, self.stockvalue.text)
class FinancialDashboard(App):
def build(self):
Window.clearcolor = (1, 1, 1, 1)
return MyStock()
if __name__ == "__main__":
FinancialDashboard().run()
还有我的 kivy 文件:
<MyStock>:
enterticker: enterticker
enterstartdate: enterstartdate
enterenddate: enterenddate
FloatLayout:
Button:
pos_hint: {"x":0.41, "y":0.9}
text: "Confirm"
font_size:14
color:0, 0, 0, 1
size_hint:0.2, 0.1
background_color:0.9, 0.9, 0.9,1
on_press: root.btn()
Label:
color: 0, 0, 0, 1
pos_hint: {"x":0.01, "y":0.9}
text: "Enter ticker"
size_hint:0.2, 0.1
TextInput:
id: enterticker
color: 0, 0, 0, 1
pos_hint: {"x":0.19, "y":0.9}
multiline:False
size_hint:0.2, 0.1
Label:
color: 0, 0, 0, 1
pos_hint: {"x":0.01, "y":0.8}
text: "Enter Start Date "
size_hint:0.2, 0.1
TextInput:
id: enterstartdate
color: 0, 0, 0, 1
pos_hint: {"x":0.19, "y":0.8}
multiline:False
size_hint:0.2, 0.1
Label:
color: 0, 0, 0, 1
pos_hint: {"x":0.01, "y":0.7}
text: "Enter End Date "
size_hint:0.2, 0.1
TextInput:
id: enterenddate
color: 0, 0, 0, 1
pos_hint: {"x":0.19, "y":0.7}
multiline:False
size_hint:0.2, 0.1
Label:
color:0, 0, 0, 1
pos_hint: {"x":0.01, "y":0.6}
text: "stockvalue"
size_hint:0.2, 0.1
带有错误信息:
File "C:\Users\xxxx\Documents\Python xxxx\OneDrive-2021-02-26\StockGUI.py", line 22, in DownloadStockData
Download = yf.download(ticker, start = starting, end = ending)
File "C:\Users\xxxx\anaconda3\lib\site-packages\yfinance\multi.py", line 71, in download
tickers, (list, set, tuple)) else tickers.replace(',', ' ').split()
File "kivy\weakproxy.pyx", line 32, in kivy.weakproxy.WeakProxy.__getattr__
AttributeError: 'TextInput' object has no attribute 'replace
'
提前致谢!!
【问题讨论】:
标签: python user-interface attributes kivy yfinance