I need to create a gui prompt line that will allow the user to enter two floats that I can then subtract

105 views Asked by At

I need to create a python gui prompt line that will allow the user to enter two floats that I can then subtract. The Entry function creates a strings and therefore i cant subtract the numbers. I tried to wrap the float() function around the creation of the input line but that doesn't seem to be allowed. Please help me create two input boxes that will alow the user to give the cost of an item (ex $4.31) and the cash given (ex 5.00) that I can subtract to find the amount that I need to make change for!

import tkinter as tk
from tkinter import *
import subprocess as sub
from tkinter import Tk, Label, Button, Entry, StringVar, DISABLED, NORMAL, END, W, E

master = Tk()

cost_label = Label(master, text="Enter Amount of Cost: $").grid(row=0)
cash_label = Label(master, text="Enter Amount of Cash: $").grid(row=1)
#WHERE I NEED HELP
cost = Entry(master)
cash = Entry(master)

cost.grid(row=0, column=1)
cash.grid(row=1, column=1)


class Change():
    def __init__(self):
        #ignore emptiness

    def changeProgram():
  #while statements to find amount depending on different dollar or coin amount
       #where im using the entries
 amount = cash - cash
        one_hundred_dollars = 0
        while amount >= 100:
            amount -= 100
            one_hundred_dollars += 1 

        fifty_dollars = 0
        while amount >= 50:
            amount -= 50
            fifty_dollars += 1 

        twenty_dollars = 0
        while amount >= 20:
            amount -= 20
            twenty_dollars += 1 

        ten_dollars = 0
        while amount >= 10:
            amount -= 10
            ten_dollars += 1 

        five_dollars = 0
        while amount >= 5:
            amount -= 5
            five_dollars += 1 

        dollars = 0
        while amount >= 1:
            amount -= 1
            dollars += 1 

# find remaining amount of change
        quarters = 0
        while amount >= .25:
            amount -= .25
            quarters += 1

        dimes = 0
        while amount >= .1:
            amount -= .1
            dimes += 1

        nickles = 0
        while amount >= .05:
            amount -= .05
            nickles += 1

# get the number of pennies
        pennies = 0
        while amount >= .01:
            pennies += 1
            amount -= .01

            return one_hundred_dollars, fifty_dollars, twenty_dollars, ten_dollars, five_dollars, dollars, quarters, dimes, nickles, pennies



    btnCalculate = Button(master, text="Calculate", fg="blue", command=changeProgram) #Calculate Button
    btnCalculate.grid(padx=100, pady = 15)

    def printoutput(one_hundred_dollars, fifty_dollars, twenty_dollars, ten_dollars, five_dollars, dollars, quarters, dimes, nickles, pennies):

        output = "1 hundred dollars %s" %(one_hundred_dollars)
        output += "\n fifty"

        messagebox.showinfo("results", output)

'''Label(master, text="One Hundred Dollars").grid(row=4)
one_hundred_dollars_output = Entry(master=None, cnf={one_hundred_dollars}, state="readonly")
one_hundred_dollars_output.grid(row=4, column=1)
one_hundred_dollars_output.set(one_hundred_dollars)'''

''' Label(master, text="Fifty").grid(row=4)

    fifty_dollars_output = Entry(master, width=20, state="readonly")
    fifty_dollars_output.grid(row=4, column=1)
    fifty_dollars_output.set(fifty_dollars)

    twenty_dollars_output = Entry(master, width=20, state="readonly")
    twenty_dollars_output.set(twenty_dollars)

    ten_dollars_output = Entry(master, width=20, state="readonly")
    ten_dollars_output.set(ten_dollars)

    five_dollars_output = Entry(master, width=20, state="readonly")
    five_dollars_output.set(five_dollars)

    dollars_output = Entry(master, width=20, state="readonly")
    dollars_output.set(dollars)

    quarters_output = Entry(master, width=20, state="readonly")
    quarters_output.set(quarters)

    dimes_output = Entry(master, width=20, state="readonly")
    dimes_output.set(dimes)

    nickles_output = Entry(master, width=20, state="readonly")
    nickles_output.set(nickles)

    pennies_output = Entry(master, width=20, state="readonly")
    pennies_output.set(pennies)


master.mainloop()'''
1

There are 1 answers

0
Robᵩ On

To fetch the data from an Entry object, call its .get() method, like so:

    amount = float(cash.get()) - float(cost.get())