Python Forum
[Tkinter] Tkinter move to next row
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Tkinter move to next row
#1
Hi all, I'm making an app that pastes receipt details into an excel spreadsheet for me & I have 2 problems that are driving me crazy!

1. For sec1: Tkinter prompts, it gives me a prompt to upload a receipt to be scanned & it works however it does not submit the receipt to the excel file until the 2nd prompt "would you like to submit another receipt" appears and I click no. This is true even if I submit 5 receipts it will only submit the first.

2. Sec3: Export to Excel. This should be simple but I can't get the data from the receipt to move down to the next column every time I submit a new receipt. It is overwriting the last receipt in the same column. I'm guessing I need either a for loop or a counter (I'm new to programming). Appreciated all!

################## Sec1: Tkinter prompts ####################################
# display message in a child window
from tkinter import *
from tkinter import filedialog

def messageWindow():
    root.filename =  filedialog.askopenfilename(initialdir = "/",title = "Select file",filetypes = (("jpeg files","*.jpg"),("all files","*.*")))
    # create child window
    win = Toplevel()
    # display message
    message = "Would you like another?"
    
    # quit child window and return to root window
    # the button is optional here, simply use the corner x of the child window
    Label(win, text=message).pack()
    Button(win, text='Yes', command=yes, ).pack()
    Button(win, text='No', command=no, ).pack()
    
    x= root.filename
   
    global h
      ## this makes the file address grabbable
    h=x
    
def yes():
    
    messageWindow()
   
    
    
def no():
    root.destroy()
    
    
# create root window
root = Tk()
# put a button on it, or a menu
Button(root, text='Upload Image', command=messageWindow).pack()

# start event-loop

root.mainloop()
################## Sec2: Receipt Recognition Section ##################


import requests


url = 'https://api.taggun.io/api/receipt/v1/simple/file'

headers = {'apikey': 'apikeyleftout'}

files = {
  'file': (
    r'{}'.format(h), # set a filename for the file
    open(r'{}'.format(h), 'rb'), # the actual file, r' is to do with text format
    'image/jpg'), # content-type for the file

  # other optional parameters for Taggun API (eg: incognito, refresh, ipAddress, language)
  'incognito': (
    None, #set filename to none for optional parameters
    'false') #value for the parameters
  }

response = requests.post(url, files=files, headers=headers)

print(response.content)


resp= response.json()  ## allows me to grab from json figures

Merchant= resp["merchantName"]   ## grabs total amount & data
Merchant_name= (Merchant["data"])  ## grabs data figure

total= resp["totalAmount"]   ## grabs total amount & data
totalvaluedata= (total["data"])  ## grabs data figure

tax= resp["taxAmount"]   ## grabs total amount & data
tax_value= (tax["data"])  ## grabs data figure
################ Sec3: Export to Excel ###############################################################
#

#
import xlsxwriter

workbook = xlsxwriter.Workbook('Receipts.xlsx')

worksheet7 = workbook.add_worksheet()



currency_format = workbook.add_format({'num_format': '$#,##0'})

# Some sample data for the table.
data = [
    [Merchant_name, tax_value, totalvaluedata]
  
  

]


caption = 'Receipts Table'

# Set the columns widths.
worksheet7.set_column('C:G', 12)
worksheet7.set_column('B:B', 50)

# Write the caption.
worksheet7.write('B1', caption)

# Add a table to the worksheet.
worksheet7.add_table('B3:D200', {'data': data,
                               'columns': [{'header': 'Merchant'},
                                           {'header': 'Tax'},
                                           {'header': 'Total'},
                                          
                                           ]})


workbook.close()
################################################################################

Output:
b'{"totalAmount":{"data":35.85,"confidenceLevel":0.83},"taxAmount":{"data":3.05,"confidenceLevel":0.9},"confidenceLevel":0.622,"date":{"confidenceLevel":0},"merchantName":{"data":"Bulk Barn","confidenceLevel":0.81},"merchantAddress":{"data":"393 King Street West, Toronto ON, Canada","confidenceLevel":0.81},"merchantTypes":{"data":["Food & Drink Shop"],"confidenceLevel":0.81}}'

No tracebacks
Reply


Messages In This Thread
Tkinter move to next row - by liamo_08 - Jul-28-2018, 02:58 PM
RE: Tkinter move to next row - by Gribouillis - Jul-28-2018, 03:30 PM
RE: Tkinter move to next row - by liamo_08 - Jul-28-2018, 03:40 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  why my list changes to a string as I move to another window in tkinter? pymn 4 3,825 Feb-17-2022, 07:02 AM
Last Post: pymn

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020