0

I want to use Tkinter funtion to create a a temperature calculator. I have all the code for the calculator, however using Tkinter function i cant figure out how to get the variable input by the users. I am new to python and programming, just started programming less then a month, so please give detailed codes. Thank you.

P.S. I'm using Python 3.2.2.

4
Contributors
4
Replies
16
Views
5 Years
Discussion Span
Last Post by Judith_2
Featured Replies
  • 1

    Tkinter's Entry widget allows the user to input a string. In your case this string has to be converted to a number for calculations. Another option for user input is to use Tkinter's pop-up dialogs that give you some control over what the user enters. Here is an example ... … Read More

0

And how then would you learn anything? See the forum rules or shorter version from my signature! There is plenty of code snippets in sticky threads and code archive for you to adapt yourself and learn how to actually do it yourself.

0

And how then would you learn anything? See the forum rules or shorter version from my signature! There is plenty of code snippets in sticky threads and code archive for you to adapt yourself and learn how to actually do it yourself.

I think I agree with you. could you tell me what I would need to do, and could you be a little specific, because the last post you were not specific. Thank You pyTony

1

Tkinter's Entry widget allows the user to input a string. In your case this string has to be converted to a number for calculations.

Another option for user input is to use Tkinter's pop-up dialogs that give you some control over what the user enters. Here is an example ...

# use Tkinter's simple pop-up dialogs to ask for input
# askfloat() for floating point numbers
# askinteger() for whole numbers
# askstring() for strings

try:
    # for Python2
    import Tkinter as tk
    import tkSimpleDialog as tksd
except ImportError:
    # for Python3
    import tkinter as tk
    import tkinter.simpledialog as tksd

root = tk.Tk()
# show input dialogs without the Tkinter window
root.withdraw()

# for numeric input use askfloat or askinteger
# widgets will prompt again if wrong value is entered
# minvalue and maxvalue are optional
price = tksd.askfloat("Price", "Enter the price of the item:")
print(price)

quantity = tksd.askinteger("Quantity", "Number of items needed:",
    minvalue=1, maxvalue=1000)
print(quantity)

result = "Total cost is %0.2f" % (price * quantity)
print(result)

# you could use askstring to display the result
sf = "%0.2f" % (price * quantity)
tksd.askstring("Result", "Total cost is:", initialvalue=sf)
0

Thank you so much. All threads describe SimpleDialog in Python 2. How to use it in Python 3 is never described. This helped a lot!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.