I have been messing around with python kivy and I have stumbled on the error as given in the title. I am trying to print the stock price of an arbirtary stock by using the yfinance package through kivy. I get the error:AttributeError: 'TextInput' object has no attribute 'replace'. Does any of you have a clue what I am doing wrong here:
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()
and my kivy file:
<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
with the error message:
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
'
thanks in advance!!
Your error text clearly indicates that you're passing a TextInput
object to something that expects to receive a string.
The culprit is then presumably:
self.stockvalue.text = self.DownloadStockData(self.enterticker, self.enterstartdate, self.enterenddate)
You likely want instead:
self.stockvalue.text = self.DownloadStockData(self.enterticker.text, self.enterstartdate.text, self.enterenddate.text)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.