Dec-29-2019, 05:13 PM
I'm not very good at programming with tkinter and kivy. To set on the old Basic, Q basic, GWBasic and VBasic for Excel and MSAccess. I've tried numerous times to make a input box for the 11 digit UPC code. I now enter a "string" before the program runs on line 9. And the "while" works when I run the code without tkinter. When I add a input box I get a "nonsubscrptible error at the" For" statements. So I gave up. I've used this same code (with modifications) for quite a few years with Access and Excel. Not important, but would like to know how to solve the problems that arise. When the code runs I do get the correct output. Received some excellent help on this forum for the "join" statements. Thank you for any help.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# Computes last (12th) number of an 11 digit UPC """completeUPC.py""" import sys import os from tkinter import * import tkinter as tk root = tk.Tk() UPCNUM = '19132910212' odd = 0 even = 0 #while UPCNUM not in range(0,9) and len(UPCNUM) != 11: #Add odd for i in range ( 0 , 11 , 2 ): odd1 = int (UPCNUM[i]) odd = odd + odd1 # multiply odd by 3 odd = odd * 3 #Add even for i in range ( 1 , 11 , 2 ): even2 = int (UPCNUM[i]) even = even + even2 #Determine last number lastnum = odd + even lastnum = lastnum % 10 lastnum = 10 - lastnum if lastnum = = 10 : lastnum = 0 #12 digit UPC finalnumber = UPCNUM + str (lastnum) #configure font code s1 = finalnumber s2 = 'PQRSTUVWXY' s3 = '0123456789' s4 = '@ABCDEFGHI' s5 = '`abcdefghi' first_str = "" last_str = "" pre_str = "" final_str = "" divdr = chr ( 112 ) pre_str = pre_str.join(s2[ int (ch)] for ch in s1[ 0 ]) first_str = first_str.join(s3[ int (ch)] for ch in s1[ 1 : 6 ]) last_str = last_str.join(s4[ int (ch)] for ch in s1[ 6 : 11 ]) final_str = final_str.join(s5[ int (ch)] for ch in s1[ 11 ]) upc_font = pre_str + first_str + divdr + last_str + final_str #Copies to clipboard r = Tk() r.withdraw() r.clipboard_clear() r.clipboard_append(upc_font) r.update() # now it stays on the clipboard after the window is closed r.destroy() #Produces label tk.Label(root, text = upc_font, relief = RAISED, borderwidth = 10 , fg = "red" , bg = "white" , font = "UPCARev 16" ).pack() #Quit button Button(root, text = "Quit" , fg = "black" , bg = "green" , font = "helvetica 16" , command = root.destroy).pack() root.mainloop() |