Rectangle 27 1

string Python AttributeError: 'str' object has no attribute 'get_price'?


import tkinter

def test_func(val):
    print(type(val))
    print(val)
    share_id = val.get()
    print(share_id)


loadApplication = tkinter.Tk()
loadApplication.title("Stock Analytics")
loadApplication.geometry("1080x720")

label1 = tkinter.Label(loadApplication, text = "Ticker")
input1 = tkinter.Entry(loadApplication)

loadAnalytics = tkinter.Button(loadApplication, text="Load Analytics", command=lambda: test_func(input1))


loadAnalytics.pack()
label1.pack()
input1.pack()

loadApplication.mainloop()
input1 = tkinter.Entry(loadApplication)

According to the effbot docs you need to use a lambda function in order to bind a function with passed arguments to a button like this:

After reading your edit, I changed ticker = Share(input1) to ticker = Share(input1.get()) and my problem was resolved! I wish I could upvote your answer twice. Thank you so much, I was working on this all day and the simplest error got me tied up. @albert

However, there is a second thing to keep in mind:

I commented it out and the program still ran.

Okay thank you! That fixed the issue of them both running! As I said earlier, I am new to this. Can you explain what the "def test_func(val): print(val)" is doing?

You need to bind a callback function to a button which is executed whenever the button is clicked. Since I was in need of a simple sample callback and do not have the yahoo_fincance module installed on my system I decided to go this way. The porgramm code is not updated 'on-line' like live-reloading. So to make any changes working and see what's the difference you need to start and restart the whole script.

Your assumption that runAnalytics is running is correct since the function is executed when binding it to the button the way you did.

creates an Entry widget called input1 which is then passed to the function. The thing is that input1 does not contain the string you typed into the entry widget but a reference to the widget (widget ID). In order to get the widget's content you need to call its .get() method as shown in my code snippet.

Note