简体   繁体   中英

I am working with Tk inter and yahoo_finance

I want to write a program such that I can enter in a pop-up entry box the stock symbol of my choice:

I know how to create an entry box in TKinter generally, but I don't know how to employ the .get() method here:

import datetime
import tkinter
from tkinter import *
import matplotlib.finance as finance

root = Tk()
E1 = Entry(root, bd=8)
E1.pack(fill=Y)
root.mainloop()
startdate = datetime.date(2013,1,1)
today = enddate = datetime.date.today()
ticker = 'I WANT THIS TO COME FROM THE ENTRY BOX '?
fh = finance.fetch_historical_yahoo(ticker, startdate, enddate)

You could use StringVar . For example

import datetime

import tkinter

from tkinter import *

import matplotlib.finance as finance

root = Tk()    

# create a StrringVar
ticker_entry_var = StringVar()

E1 = Entry(root, bd=8, textvariable=ticker_entry_var)

E1.pack(fill=Y)

root.mainloop()

startdate = datetime.date(2013,1,1) 
today = enddate = datetime.date.today()

# get value from the entry box 
ticker = ticker_entry_var.get()
print(ticker)

Now, when you close the tk window, ticker will have the value from the stringvar.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM