1

I have some fairly simple code to get values for a urlstring.

I have looked at all the other questions and cant seem to find a relevant answer I can apply

Some of the code comes up first in the Ipython console which I expect and will change later and I do get a value in Ipython console from the hardcoded variables on button press but cant seem to get value of text boxes into the variables and then use them instead?

amount = '1'
cur1 = input('What Currency would you like to trade from? ')
cur2 = input('What Currency would you like to trade to? ')
cur1_1 = StringVar()
cur2_1 = StringVar()
#i = 0 


#Textboxes for user input
txtcur1 = Entry(root, font="Helvetica 11 bold",bg="white", width=6, textvariable=cur1_1)
txtcur1.place(x=110, y=50)
txtcur2 = Entry(root, font="Helvetica 11 bold",bg="white", width=6, textvariable=cur2_1)
txtcur2.place(x=110, y=75)
#End


def results():
    t = datetime.utcnow()  
    url1  = "http://www.xe.com/currencyconverter/convert/" + "?Amount=" + amount + "&From=" + cur1 + "&To=" + cur2
    url2 = "http://www.xe.com/currencyconverter/convert/" + "?Amount=" + amount + "&From=" + cur2_1 + "&To=" + cur1_1

But for the life of me I cant get the variables from the textboxes into the variables cur1_1 and cur2_1 and am getting the typeerror.

url2 = "http://www.xe.com/currencyconverter/convert/" + "?Amount=" + amount + "&From=" + cur2_1 + "&To=" + cur1_1
TypeError: must be str, not StringVar

When I change it to string it says must be 3 digit long I would have thought It would have been a bit simpler than this. Any help please?

Also once I have the returned values for the exchange rates I need them to be converted to a decimal to 9 places and displayed with commas for monetary use .

Full code here https://pastebin.com/uPWyPXMZ

8
  • You've posted too much code. Please try to reduce it down to a minimal reproducible example Commented Aug 19, 2017 at 4:28
  • i did try but it got too confusing Commented Aug 19, 2017 at 4:29
  • and i have seen much longer ones when researching other questions like this Commented Aug 19, 2017 at 4:30
  • THROWS COMPUTER AT WALL IN FRUSTRATION Commented Aug 19, 2017 at 4:31
  • could you give me an example of what that would look like to you with this code instead of just saying i should do it... tell someone to get it right or show someone how to get it right which one do you think teaches people better? Commented Aug 19, 2017 at 4:32

1 Answer 1

3

Your problem seems to be you're using cur1_1 and cur2_1 as if they were strings when you should be calling their StringVar.get() methods to access their string values.

A simple-minded example:

import tkinter as tk

def show_text():
    label_text.set('Heh, heh, heh, you said, "' + entry_text.get() + '"')

root = tk.Tk()

entry_text = tk.StringVar()
entry = tk.Entry(root, width=10, textvariable=entry_text)
entry.pack()

button = tk.Button(root, text="Click Me", command=show_text)
button.pack()

label_text = tk.StringVar()
label = tk.Label(root, textvariable=label_text)
label.pack()

root.mainloop()

Put text in the entry box, and click the button. The text will be transfered from the entry box to the label via the .get() method of the StringVar associated with the Entry when it was created.

Sign up to request clarification or add additional context in comments.

4 Comments

to convert the return vals to decimals simply returned_val = Decimal (thevalue.get())???
@GoulouhAnwar, I would say int(thevalue.get()) or float(thevalue.get()) depending what you need. From where are you importing Decimal()?
from decimal import Decimal havent added yet \
I have aprivate chat between myself and skrx I would be honored if you would join if yu felt like answering my n00b questions karma is always karma

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.