Build a GUI Application to Get Live Stock Price using Python

The stock price is the highest amount someone is willing to pay for the stock. In this article, we are going to write code for getting live share prices for each company and bind with GUI Application.

Module Needed

Yahoo_fin: This module is used to scrape historical stock price data, as well as to provide current information on market caps, dividend yields, and which stocks comprise the major exchanges. To install this module type the below command in the terminal.

pip install yahoo_fin

Let’s write code to get stock data.

Import the yahoo_fin module.

Python3



filter_none

edit
close

play_arrow

link
brightness_4
code

from yahoo_fin import stock_info

chevron_right


Use stock_info.get_live_price() method to get live stock price.

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

stock_info.get_live_price("AMZN")

chevron_right


Output:

3198.93994140625

Note: please visit this site to get company Symbol like Amazon is AMZN, Reliance is RELFF.

Stock price Application with Tkinter

This Script implements the above Implementation into a GUI.

Python3

filter_none

edit
close

play_arrow

link
brightness_4
code

from yahoo_fin import stock_info
from tkinter import *
  
  
def stock_price():
  
    price = stock_info.get_live_price(e1.get())
    Current_stock.set(price)
  
  
master = Tk()
Current_stock = StringVar()
  
Label(master, text="Company Symbol : ").grid(row=0, sticky=W)
Label(master, text="Stock Result:").grid(row=3, sticky=W)
  
result2 = Label(master, text="", textvariable=Current_stock,
                ).grid(row=3, column=1, sticky=W)
  
e1 = Entry(master)
e1.grid(row=0, column=1)
  
b = Button(master, text="Show", command=stock_price)
b.grid(row=0, column=2, columnspan=2, rowspan=2, padx=5, pady=5)
  
mainloop()

chevron_right


Output:


Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.