130k views
4 votes
Write a GUI program that calculates the average of what an employee earns in tips per hour. The program’s window should have Entry (font: Courier New) widgets that let the user enter the number of hours they worked and amount they earned in tips during they time. When a Calculate button is clicked, the program should display the average amount they got paid in tips per hour. Use the following formula: Tips per hour = amount of tips in dollars / hours.

User Martiendt
by
5.5k points

1 Answer

2 votes

Answer:

Step-by-step explanation:

Using Code:

from tkinter import *

#object of Tk class to make GUI

root = Tk()

#creating a canvas to put labels, entries and button

canvas1 = Canvas(root, width = 300, tallness = 200)

canvas1.pack()

#label for number of hours worked

label1 = Label(root, text = "Hours : ", textual style = ('Courier', 10))

canvas1.create_window(80, 50, window = label1)

#entry for number of hours worked

entry1 = Entry(root, textual style = ('Courier', 10))

canvas1.create_window(200, 50, window = entry1)

#label for sum they earned in tips

label2 = Label(root, text = "Tips : ", textual style = ('Courier', 10))

canvas1.create_window(80, 80, window = label2)

#entry for sum they earned in tips

entry2 = Entry(root, text style = ('Courier', 10))

canvas1.create_window(200, 80, window = entry2)

#label for tips every hour

label3 = Label(root, text = "Tips Per Hour : ", textual style = ('Courier', 10))

canvas1.create_window(80, 150, window = label3)

#function to figure tips every hour

def TipsPerHour():

#getting estimation of hour

hours = int(entry1.get())

#getting estimation of tips

tips = int(entry2.get())

#calculating normal sum got paid in tips every hour

normal = tips/hours

#creating a name to show normal

label4 = Label(root, text = "$" + str(average), textual style = ('Courier', 10))

canvas1.create_window(170, 150, window = label4)

#button for compute

calculateButton = Button(root, text = "Compute", textual style = ('Courier', 10), order = TipsPerHour)

canvas1.create_window(170, 110, window = calculateButton)

#mainloop

root.mainloop()

User Shahab Rauf
by
4.9k points