0

I've been to build a time card calculator for my sister to use at her job, and the only thing I have left to do on it is make the print button functional.

I have it set up so she can put in the name, pay period start and end, pay date, and all of the clock in and out times. it then adds everything together and puts it into a tkinter label, and puts the grand total of all shifts at the bottom.

I need to try and print all of the information out using the printer but im not sure what the best way is to make this function.

also, im writing the code on OS X, but she'll be using it on windows so I don't need it to be functional on mac.

import tkinter as tkr

root = tkr.Tk()

windowWidth = root.winfo_reqwidth()
windowHeight = root.winfo_reqheight()
positionRight = int(root.winfo_screenwidth()/2 - windowWidth/2)
positionDown = int(root.winfo_screenheight()/2 - windowHeight/2)

root.title("Time Card Calculator")
root.geometry( "+{}+{}".format(positionRight, positionDown))
root.resizable(0,0)
root.configure(background='grey33')

labelfont = ('calibri', 35)

header = tkr.Label(root, text="Time Card Calculator", background="grey33")
header.config(font=labelfont)
header.config(fg="snow")
header.grid(row=0, columnspan=3)

smallfont = ('calibri', 20)

firstlabel = tkr.Label(root, text="Employee first name", background="gray33")
firstlabel.config(font=smallfont)
firstlabel.config(fg="snow")
firstlabel.grid(row=1, column=0)

lastlabel = tkr.Label(root, text="Employee last name", background="gray33")
lastlabel.config(font=smallfont)
lastlabel.config(fg="snow")
lastlabel.grid(row=1, column=2)

startlabel = tkr.Label(root, text="Pay start", background="grey33")
startlabel.config(font=smallfont)
startlabel.config(fg="snow")
startlabel.grid(row=3, column=0)

endlabel = tkr.Label(root, text="Pay end", background="grey33")
endlabel.config(font=smallfont)
endlabel.config(fg="snow")
endlabel.grid(row=3, column=1)

datelabel = tkr.Label(root, text="Pay date", background="grey33")
datelabel.config(font=smallfont)
datelabel.config(fg="snow")
datelabel.grid(row=3, column=2)

inlabel = tkr.Label(root, text="Time In", background="grey33")
inlabel.config(font=smallfont)
inlabel.config(fg="snow")
inlabel.grid(row=5, column=0)

outlabel = tkr.Label(root, text="Time Out", background="grey33")
outlabel.config(font=smallfont)
outlabel.config(fg="snow")
outlabel.grid(row=5, column=1)

totallabel = tkr.Label(root, text="Total", background="grey33")
totallabel.config(font=smallfont)
totallabel.config(fg="snow")
totallabel.grid(row=5, column=2)

time_1_var = tkr.StringVar(root)
time_2_var = tkr.StringVar(root)
time_3_var = tkr.StringVar(root)
time_4_var = tkr.StringVar(root)
time_5_var = tkr.StringVar(root)
time_6_var = tkr.StringVar(root)
time_7_var = tkr.StringVar(root)
time_8_var = tkr.StringVar(root)
time_9_var = tkr.StringVar(root)
time_10_var = tkr.StringVar(root)
time_11_var = tkr.StringVar(root)
time_12_var = tkr.StringVar(root)
time_13_var = tkr.StringVar(root)
time_14_var = tkr.StringVar(root)
time_15_var = tkr.StringVar(root)
time_16_var = tkr.StringVar(root)
grand_total_var = tkr.StringVar(root)

zero = str(0)

first_name = tkr.Entry(root, highlightbackground="grey33")
last_name = tkr.Entry(root, highlightbackground="grey33")
pay_start = tkr.Entry(root, highlightbackground="grey33")
pay_end = tkr.Entry(root, highlightbackground="grey33")
pay_date = tkr.Entry(root, highlightbackground="grey33")
time_in1 = tkr.Entry(root, highlightbackground="grey33")
time_in1.insert(0, zero)
time_out1 = tkr.Entry(root, highlightbackground="grey33")
time_out1.insert(0, zero)
time_1_total = tkr.Label(root, textvariable = time_1_var, background="grey33")
time_1_var.set('')
time_in2 = tkr.Entry(root, highlightbackground="grey33")
time_in2.insert(0, zero)
time_out2 = tkr.Entry(root, highlightbackground="grey33")
time_out2.insert(0, zero)
time_2_total = tkr.Label(root, textvariable = time_2_var, background="grey33")
time_2_var.set('')
time_in3 = tkr.Entry(root, highlightbackground="grey33")
time_in3.insert(0, zero)
time_out3 = tkr.Entry(root, highlightbackground="grey33")
time_out3.insert(0, zero)
time_3_total = tkr.Label(root, textvariable=time_3_var, background="grey33")
time_3_var.set('')
time_in4 = tkr.Entry(root, highlightbackground="grey33")
time_in4.insert(0, zero)
time_out4 = tkr.Entry(root, highlightbackground="grey33")
time_out4.insert(0, zero)
time_4_total = tkr.Label(root, textvariable=time_4_var, background="grey33")
time_4_var.set('')
time_in5 = tkr.Entry(root, highlightbackground="grey33")
time_in5.insert(0, zero)
time_out5 = tkr.Entry(root, highlightbackground="grey33")
time_out5.insert(0, zero)
time_5_total = tkr.Label(root, textvariable=time_5_var, background="grey33")
time_5_var.set('')
time_in6 = tkr.Entry(root, highlightbackground="grey33")
time_in6.insert(0, zero)
time_out6 = tkr.Entry(root, highlightbackground="grey33")
time_out6.insert(0, zero)
time_6_total = tkr.Label(root, textvariable=time_6_var, background="grey33")
time_6_var.set('')
time_in7 = tkr.Entry(root, highlightbackground="grey33")
time_in7.insert(0, zero)
time_out7 = tkr.Entry(root, highlightbackground="grey33")
time_out7.insert(0, zero)
time_7_total = tkr.Label(root, textvariable=time_7_var, background="grey33")
time_7_var.set('')
time_in8 = tkr.Entry(root, highlightbackground="grey33")
time_in8.insert(0, zero)
time_out8 = tkr.Entry(root, highlightbackground="grey33")
time_out8.insert(0, zero)
time_8_total = tkr.Label(root, textvariable=time_8_var, background="grey33")
time_8_var.set('')
time_in9 = tkr.Entry(root, highlightbackground="grey33")
time_in9.insert(0, zero)
time_out9 = tkr.Entry(root, highlightbackground="grey33")
time_out9.insert(0, zero)
time_9_total = tkr.Label(root, textvariable=time_9_var, background="grey33")
time_9_var.set('')
time_in10 = tkr.Entry(root, highlightbackground="grey33")
time_in10.insert(0, zero)
time_out10 = tkr.Entry(root, highlightbackground="grey33")
time_out10.insert(0, zero)
time_10_total = tkr.Label(root, textvariable=time_10_var, background="grey33")
time_10_var.set('')
time_in11 = tkr.Entry(root, highlightbackground="grey33")
time_in11.insert(0, zero)
time_out11 = tkr.Entry(root, highlightbackground="grey33")
time_out11.insert(0, zero)
time_11_total = tkr.Label(root, textvariable=time_11_var, background="grey33")
time_11_var.set('')
time_in12 = tkr.Entry(root, highlightbackground="grey33")
time_in12.insert(0, zero)
time_out12 = tkr.Entry(root, highlightbackground="grey33")
time_out12.insert(0, zero)
time_12_total = tkr.Label(root, textvariable=time_12_var, background="grey33")
time_12_var.set('')
time_in13 = tkr.Entry(root, highlightbackground="grey33")
time_in13.insert(0, zero)
time_out13 = tkr.Entry(root, highlightbackground="grey33")
time_out13.insert(0, zero)
time_13_total = tkr.Label(root, textvariable=time_13_var, background="grey33")
time_13_var.set('')
time_in14 = tkr.Entry(root, highlightbackground="grey33")
time_in14.insert(0, zero)
time_out14 = tkr.Entry(root, highlightbackground="grey33")
time_out14.insert(0, zero)
time_14_total = tkr.Label(root, textvariable=time_14_var, background="grey33")
time_14_var.set('')
time_in15 = tkr.Entry(root, highlightbackground="grey33")
time_in15.insert(0, zero)
time_out15 = tkr.Entry(root, highlightbackground="grey33")
time_out15.insert(0, zero)
time_15_total = tkr.Label(root, textvariable=time_15_var, background="grey33")
time_15_var.set('')
time_in16 = tkr.Entry(root, highlightbackground="grey33")
time_in16.insert(0, zero)
time_out16 = tkr.Entry(root, highlightbackground="grey33")
time_out16.insert(0, zero)
time_16_total = tkr.Label(root, textvariable=time_16_var, background="grey33")
time_16_var.set('')
grand_total = tkr.Label(root, textvariable=grand_total_var, background="grey33")
grand_total_var.set('')


first_name.grid(row=2, column=0, padx=15)
last_name.grid(row=2, column=2, padx=15)
pay_start.grid(row=4, column=0, padx=15)
pay_end.grid(row=4, column=1, padx=15)
pay_date.grid(row=4, column=2, padx=15)
time_in1.grid(row=6, column=0, padx=15)
time_out1.grid(row=6, column=1, padx=15)
time_1_total.config(font=smallfont)
time_1_total.config(fg="snow")
time_1_total.grid(row=6, column=2, padx=15)
time_in2.grid(row=7, column=0, padx=15)
time_out2.grid(row=7, column=1, padx=15)
time_2_total.grid(row=7, column=2, padx=15)
time_2_total.config(font=smallfont)
time_2_total.config(fg="snow")
time_in3.grid(row=8, column=0, padx=15)
time_out3.grid(row=8, column=1, padx=15)
time_3_total.grid(row=8, column=2, padx=15)
time_3_total.config(font=smallfont)
time_3_total.config(fg="snow")
time_in4.grid(row=9, column=0, padx=15)
time_out4.grid(row=9, column=1, padx=15)
time_4_total.grid(row=9, column=2, padx=15)
time_4_total.config(font=smallfont)
time_4_total.config(fg="snow")
time_in5.grid(row=10, column=0, padx=15)
time_out5.grid(row=10, column=1, padx=15)
time_5_total.grid(row=10, column=2, padx=15)
time_5_total.config(font=smallfont)
time_5_total.config(fg="snow")
time_in6.grid(row=11, column=0, padx=15)
time_out6.grid(row=11, column=1, padx=15)
time_6_total.grid(row=11, column=2, padx=15)
time_6_total.config(font=smallfont)
time_6_total.config(fg="snow")
time_in7.grid(row=12, column=0, padx=15)
time_out7.grid(row=12, column=1, padx=15)
time_7_total.grid(row=12, column=2, padx=15)
time_7_total.config(font=smallfont)
time_7_total.config(fg="snow")
time_in8.grid(row=13, column=0, padx=15)
time_out8.grid(row=13, column=1, padx=15)
time_8_total.grid(row=13, column=2, padx=15)
time_8_total.config(font=smallfont)
time_8_total.config(fg="snow")
time_in9.grid(row=14, column=0, padx=15)
time_out9.grid(row=14, column=1, padx=15)
time_9_total.grid(row=14, column=2, padx=15)
time_9_total.config(font=smallfont)
time_9_total.config(fg="snow")
time_in10.grid(row=15, column=0, padx=15)
time_out10.grid(row=15, column=1, padx=15)
time_10_total.grid(row=15, column=2, padx=15)
time_10_total.config(font=smallfont)
time_10_total.config(fg="snow")
time_in11.grid(row=16, column=0, padx=15)
time_out11.grid(row=16, column=1, padx=15)
time_11_total.grid(row=16, column=2, padx=15)
time_11_total.config(font=smallfont)
time_11_total.config(fg="snow")
time_in12.grid(row=17, column=0, padx=15)
time_out12.grid(row=17, column=1, padx=15)
time_12_total.grid(row=17, column=2, padx=15)
time_12_total.config(font=smallfont)
time_12_total.config(fg="snow")
time_in13.grid(row=18, column=0, padx=15)
time_out13.grid(row=18, column=1, padx=15)
time_13_total.grid(row=18, column=2, padx=15)
time_13_total.config(font=smallfont)
time_13_total.config(fg="snow")
time_in14.grid(row=19, column=0, padx=15)
time_out14.grid(row=19, column=1, padx=15)
time_14_total.grid(row=19, column=2, padx=15)
time_14_total.config(font=smallfont)
time_14_total.config(fg="snow")
time_in15.grid(row=20, column=0, padx=15)
time_out15.grid(row=20, column=1, padx=15)
time_15_total.grid(row=20, column=2, padx=15)
time_15_total.config(font=smallfont)
time_15_total.config(fg="snow")
time_in16.grid(row=21, column=0, padx=15)
time_out16.grid(row=21, column=1, padx=15)
time_16_total.grid(row=21, column=2, padx=15)
time_16_total.config(font=smallfont)
time_16_total.config(fg="snow")
grand_total.grid(row=22, columnspan=3, padx=15)
grand_total.config(font=smallfont)
grand_total.config(fg="snow")

def clear():
    first_name.delete(0, 'end')
    last_name.delete(0, 'end')
    time_in1.delete(0, 'end')
    time_in1.insert(0, zero)
    time_out1.delete(0, 'end')
    time_out1.insert(0, zero)
    time_1_var.set('')
    time_in2.delete(0, 'end')
    time_in2.insert(0, zero)
    time_out2.delete(0, 'end')
    time_out2.insert(0, zero)
    time_2_var.set('')
    time_in3.delete(0, 'end')
    time_in3.insert(0, zero)
    time_out3.delete(0, 'end')
    time_out3.insert(0, zero)
    time_3_var.set('')
    time_in4.delete(0, 'end')
    time_in4.insert(0, zero)
    time_out4.delete(0, 'end')
    time_out4.insert(0, zero)
    time_4_var.set('')
    time_in5.delete(0, 'end')
    time_in5.insert(0, zero)
    time_out5.delete(0, 'end')
    time_out5.insert(0, zero)
    time_5_var.set('')
    time_in6.delete(0, 'end')
    time_in6.insert(0, zero)
    time_out6.delete(0, 'end')
    time_out6.insert(0, zero)
    time_6_var.set('')
    time_in7.delete(0, 'end')
    time_in7.insert(0, zero)
    time_out7.delete(0, 'end')
    time_out7.insert(0, zero)
    time_7_var.set('')
    time_in8.delete(0, 'end')
    time_in8.insert(0, zero)
    time_out8.delete(0, 'end')
    time_out8.insert(0, zero)
    time_8_var.set('')
    time_in9.delete(0, 'end')
    time_in9.insert(0, zero)
    time_out9.delete(0, 'end')
    time_out9.insert(0, zero)
    time_9_var.set('')
    time_in10.delete(0, 'end')
    time_in10.insert(0, zero)
    time_out10.delete(0, 'end')
    time_out10.insert(0, zero)
    time_10_var.set('')
    time_in11.delete(0, 'end')
    time_in11.insert(0, zero)
    time_out11.delete(0, 'end')
    time_out11.insert(0, zero)
    time_11_var.set('')
    time_in12.delete(0, 'end')
    time_in12.insert(0, zero)
    time_out12.delete(0, 'end')
    time_out12.insert(0, zero)
    time_12_var.set('')
    time_in13.delete(0, 'end')
    time_in13.insert(0, zero)
    time_out13.delete(0, 'end')
    time_out13.insert(0, zero)
    time_13_var.set('')
    time_in14.delete(0, 'end')
    time_in14.insert(0, zero)
    time_out14.delete(0, 'end')
    time_out14.insert(0, zero)
    time_14_var.set('')
    time_in15.delete(0, 'end')
    time_in15.insert(0, zero)
    time_out15.delete(0, 'end')
    time_out15.insert(0, zero)
    time_15_var.set('')
    time_in16.delete(0, 'end')
    time_in16.insert(0, zero)
    time_out16.delete(0, 'end')
    time_out16.insert(0, zero)
    time_16_var.set('')
    grand_total_var.set('')


def calculate():

    fields = time_in1.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalin1 = float(hours) + (float(minutes) / 60.0)

    fields = time_out1.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalout1 = float(hours) + (float(minutes) / 60.0)

    grandtotal1 = totalout1 - totalin1
    grandtotal1 = round(grandtotal1, 3)

    fields = time_in2.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalin2 = float(hours) + (float(minutes) / 60.0)

    fields = time_out2.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalout2 = float(hours) + (float(minutes) / 60.0)

    grandtotal2 = totalout2 - totalin2
    grandtotal2 = round(grandtotal2, 3)

    fields = time_in3.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalin3 = float(hours) + (float(minutes) / 60.0)

    fields = time_out3.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalout3 = float(hours) + (float(minutes) / 60.0)

    grandtotal3 = totalout3 - totalin3
    grandtotal3 = round(grandtotal3, 3)

    fields = time_in4.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalin4 = float(hours) + (float(minutes) / 60.0)

    fields = time_out4.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalout4 = float(hours) + (float(minutes) / 60.0)

    grandtotal4 = totalout4 - totalin4
    grandtotal4 = round(grandtotal4, 3)

    fields = time_in5.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalin5 = float(hours) + (float(minutes) / 60.0)

    fields = time_out5.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalout5 = float(hours) + (float(minutes) / 60.0)

    grandtotal5 = totalout5 - totalin5
    grandtotal5 = round(grandtotal5, 3)

    fields = time_in6.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalin6 = float(hours) + (float(minutes) / 60.0)

    fields = time_out6.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalout6 = float(hours) + (float(minutes) / 60.0)

    grandtotal6 = totalout6 - totalin6
    grandtotal6 = round(grandtotal6, 3)

    fields = time_in7.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalin7 = float(hours) + (float(minutes) / 60.0)

    fields = time_out7.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalout7 = float(hours) + (float(minutes) / 60.0)

    grandtotal7 = totalout7 - totalin7
    grandtotal7 = round(grandtotal7, 3)

    fields = time_in8.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalin8 = float(hours) + (float(minutes) / 60.0)

    fields = time_out8.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalout8 = float(hours) + (float(minutes) / 60.0)

    grandtotal8 = totalout8 - totalin8
    grandtotal8 = round(grandtotal8, 3)

    fields = time_in9.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalin9 = float(hours) + (float(minutes) / 60.0)

    fields = time_out9.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalout9 = float(hours) + (float(minutes) / 60.0)

    grandtotal9 = totalout9 - totalin9
    grandtotal9 = round(grandtotal9, 3)

    fields = time_in10.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalin10 = float(hours) + (float(minutes) / 60.0)

    fields = time_out10.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalout10 = float(hours) + (float(minutes) / 60.0)

    grandtotal10 = totalout10 - totalin10
    grandtotal10 = round(grandtotal10, 3)

    fields = time_in11.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalin11 = float(hours) + (float(minutes) / 60.0)

    fields = time_out11.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalout11 = float(hours) + (float(minutes) / 60.0)

    grandtotal11 = totalout11 - totalin11
    grandtotal11 = round(grandtotal11, 3)

    fields = time_in12.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalin12 = float(hours) + (float(minutes) / 60.0)

    fields = time_out12.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalout12 = float(hours) + (float(minutes) / 60.0)

    grandtotal12 = totalout12 - totalin12
    grandtotal12 = round(grandtotal12, 3)

    fields = time_in13.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalin13 = float(hours) + (float(minutes) / 60.0)

    fields = time_out13.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalout13 = float(hours) + (float(minutes) / 60.0)

    grandtotal13 = totalout13 - totalin13
    grandtotal13 = round(grandtotal13, 3)

    fields = time_in14.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalin14 = float(hours) + (float(minutes) / 60.0)

    fields = time_out14.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalout14 = float(hours) + (float(minutes) / 60.0)

    grandtotal14 = totalout14 - totalin14
    grandtotal14 = round(grandtotal14, 3)

    fields = time_in15.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalin15 = float(hours) + (float(minutes) / 60.0)

    fields = time_out15.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalout15 = float(hours) + (float(minutes) / 60.0)

    grandtotal15 = totalout15 - totalin15
    grandtotal15 = round(grandtotal15, 3)

    fields = time_in16.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalin16 = float(hours) + (float(minutes) / 60.0)

    fields = time_out16.get().split(":")
    hours = fields[0] if len(fields) > 0 else 0.0
    minutes = fields[1] if len(fields) > 1 else 0.0
    totalout16 = float(hours) + (float(minutes) / 60.0)

    grandtotal16 = totalout16 - totalin16
    grandtotal16 = round(grandtotal16, 3)

    time_1_var.set(grandtotal1)
    time_2_var.set(grandtotal2)
    time_3_var.set(grandtotal3)
    time_4_var.set(grandtotal4)
    time_5_var.set(grandtotal5)
    time_6_var.set(grandtotal6)
    time_7_var.set(grandtotal7)
    time_8_var.set(grandtotal8)
    time_9_var.set(grandtotal9)
    time_10_var.set(grandtotal10)
    time_11_var.set(grandtotal11)
    time_12_var.set(grandtotal12)
    time_13_var.set(grandtotal13)
    time_14_var.set(grandtotal14)
    time_15_var.set(grandtotal15)
    time_16_var.set(grandtotal16)

    grandtotalall = (grandtotal1 + grandtotal2 + grandtotal3 + grandtotal4 + grandtotal5 + grandtotal6 + grandtotal7 +
                    grandtotal8 + grandtotal9 + grandtotal10 + grandtotal11 + grandtotal12 + grandtotal13 +
                    grandtotal14 + grandtotal15 + grandtotal16)

    grand_total_var.set(grandtotalall)




def printer():
    pass

button_clear = tkr.Button(root, width=15, height=2, background="deepskyblue", fg="black",
                          highlightbackground="dodgerblue2", text="Clear", command=clear)
button_clear.grid(row=23, column=0, padx=15, pady=5)
button_calculate = tkr.Button(root, width=15, height=2, background="grey33", highlightbackground="dodgerblue2",
                              text="Calculate", command=calculate)
button_calculate.grid(row=23, column=1, padx=15, pady=5)
button_print = tkr.Button(root, width=15, height=2, background="grey33", highlightbackground="dodgerblue2",
                          text="Print", command=printer)
button_print.grid(row=23, column=2, padx=15, pady=5)

tkr.mainloop()
Gadawg099
  • 117
  • 1
  • 3
  • 15
  • 2
    As an aside, you should probably refactor your code to use some loops and data structures, it looks like there is a lot of repeated code. – AMC Mar 01 '20 at 00:47
  • AFAIK there's nothing in Tk capable of printing. You will need to construct a document you want to print, then print it out yourself. There are various methods to do that, depending on what exactly you want to do. [This](http://timgolden.me.uk/python/win32_how_do_i/print.html) is the best reference I know of about printing from Python in Windows (I haven't seen a Stack Overflow equivalent). – Amadan Mar 01 '20 at 00:52
  • @AMC was going to make the same comment – Derek Eden Mar 01 '20 at 00:54
  • @AMC that's something Ive been trying to figure out how to do. I knew there had to be a better way to do what I was doing, I just couldn't really figure it out. is there anywhere specific you suggest I go to learn that? – Gadawg099 Mar 01 '20 at 01:23
  • On Linux (and maybe on OS X too) you can use program `lpr` to send file to printer. [Command-Line Printing and Options](https://www.cups.org/doc/options.html). Maybe Windows has similar program. BTW: `lpr` uses server `CUPS` and there should be python module to work with `CUPS` [pycups](https://pypi.org/project/pycups/) – furas Mar 01 '20 at 01:26
  • You can take a screenshot of the root window and save it to a file. Then run the command `mspaint /pt \path\to\image\file` via `os.system()`. – acw1668 Mar 01 '20 at 02:32

1 Answers1

0

You can print with HtmlEasyPrint (even if you're just printing text), with just a few simple lines of code.

To install, with Windows or Linux type

pip install wxpython

into the command prompt. Go here for how to install on OSx: How do I install pip on macOS or OS X?

Here is the python code:

import wx
from wx.html import HtmlEasyPrinting
app = wx.App(redirect=True)

sample = 'Hello, this is a test print.<br>This is a separate line.'

MyPrint = HtmlEasyPrinting()

MyPrint.PrintText(sample)

app.MainLoop()
David
  • 5
  • 3