Python Forum
[Tkinter] Input box
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Input box
#1
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.
# 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()
Reply


Messages In This Thread
Input box - by Jpen10 - Dec-29-2019, 05:13 PM
RE: Input box - by woooee - Dec-29-2019, 08:04 PM
RE: Input box - by Jpen10 - Dec-29-2019, 08:43 PM
RE: Input box - by woooee - Dec-30-2019, 06:26 PM
RE: Input box - by Jpen10 - Dec-30-2019, 09:56 PM
RE: Input box - by joe_momma - Dec-31-2019, 09:15 PM
RE: Input box - by Jpen10 - Jan-01-2020, 05:37 PM
RE: Input box - by Jpen10 - Jan-27-2020, 04:02 PM

Forum Jump:

User Panel Messages

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