Hi,

This is my first post so I hope I explain myself well. I just started learning how to program about three weeks ago.
I chose python becuase SPSS now can interface with Python. So this may seem like an obvious question.

What I am trying to do is set up an entry widget that allows only 11 characters which I learned how to do for a different entry widget. Now I want to put two "/" in the widget as separators for a date. I know how to insert the the "/" but they appear at the front of the widget even after specifying where they should appear. Does anyone have any ideas of 1)how to place them in the correct spots and 2) make them so they can not be deleted by the users.

here is my code

class MyApp:
	def __init__(self, parent):
		self.myParent=parent
		self.myContainer1=Frame(parent)
		self.myContainer1.pack()

                                self.DOBFrame=Frame(self.myContainer1)
		self.DOBFrame.pack(side=TOP)

                                self.DOBVAR=StringVar()
                               
                                self.dobtext=Label(self.DOBFrame,   text="Offender Date of Birth (mm/dd/yyyy)")
		self.dobtext.pack(side=LEFT)

		self.dob=Entry(self.DOBFrame, width=11, relief=SUNKEN, textvariable=self.DOBVAR)
		self.dob.pack(side=LEFT)
		self.dob.insert(2, "/")
		self.dob.insert(5, "/")

root=Tk()
root.title('CJAD SCS Survey')
myapp=MyApp(root)
root.mainloop()

Thanks in advance for any help.

Do all of us, including yourself, a favor and don't mix tabs and spaces for the 'all important' Python code indentations. Stick with spaces, since tabs depend on the editor settings. Most Python editors can be set to this feature.

As for your date entry you could use something like this ...

# Tkinter enter a date
 
import Tkinter as tk
 
def makedate(e):
    # create the date string from the 3 entry widgets
    date = "%s/%s/%s" % (en1.get(), en2.get(), en3.get())
    # show it
    root.title(date)
 
root = tk.Tk()
root.title('title')
 
label1 = tk.Label(root, text="Date of Birth (mm/dd/yyyy)")
label1.pack(side='left')
 
en1 = tk.Entry(root, width=2)
en1.pack(side='left')
tk.Label(root, text='/').pack(side='left')
en2 = tk.Entry(root, width=2)
en2.pack(side='left')
tk.Label(root, text='/').pack(side='left')
en3 = tk.Entry(root, width=4)
en3.pack(side='left')

en1.focus()

# make each entry responsive to the enter key
en1.bind('<Return>', func=lambda e: en2.focus_set())
en2.bind('<Return>', func=lambda e: en3.focus_set())
en3.bind('<Return>', func=makedate)
 
root.mainloop()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.