Python Forum
[Tkinter] Thousand Separator Entry Widget Cursor Pos Trouble
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Thousand Separator Entry Widget Cursor Pos Trouble
#1
how to fix cursor pos?

def atPos(atX=0,atY=0):
   frame = Frame(root)
   frame.place(x=atX,y=atY)
   return frame

class MyEntry:
   def __init__(self,parent):
       self.frame = Frame(parent, width=150,height=24)
       self.frame.pack_propagate(False)
       self.frame.pack()
       self.var = StringVar()
       self.var.trace("w", self.thousandseparator)
       self.vcmd = (self.frame.register(self.onValidate),'%d', '%P', '%S')
       self.entry = Entry(self.frame,textvariable=self.var, validate="all", validatecommand=self.vcmd)
       self.entry.pack(fill=BOTH,expand=True)

   def onValidate(self, d, P, S):
       if d=='1':
           if S in '0123456789':
               return True
           else:
               return False
       else:
           return True

   def thousandseparator(self,*arg):
       self.pra = self.var.get()
       self.buff = self.pra.replace(',','')
       if len(self.buff) > 0:
           self.value = int(self.buff)
           self.change = "{:,}".format(self.value)
           self.var.set(self.change)

if __name__ == '__main__':
   import locale
   from tkinter import *

   root = Tk()
   root.geometry('325x120+50+50')

   pos10 = atPos(15,10)
   label1 = Label(pos10,text='Type Number Only').pack()
   pos11 = atPos(150, 10)
   entry = MyEntry(pos11)

   pos20 = atPos(15,37)
   label2 = Label(pos20,text='Type Number again').pack()
   pos21 = atPos(150, 37)
   entry = MyEntry(pos21)

   pos3 = atPos(150,80)
   Exit = Button(pos3,text=' Exit ',command=lambda : quit()).pack()

   root.mainloop()
Reply


Messages In This Thread
Thousand Separator Entry Widget Cursor Pos Trouble - by papatubies - Jul-24-2017, 10:14 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ValueError: could not convert string to float: '' fron Entry Widget russellm44 5 836 Mar-06-2024, 08:42 PM
Last Post: russellm44
  [Tkinter] entry widget DPaul 5 1,602 Jul-28-2023, 02:31 PM
Last Post: deanhystad
  [Tkinter] Take the variable of a cursor class delcencen 2 1,222 Feb-13-2023, 05:19 AM
Last Post: deanhystad
  Tkinter Exit Code based on Entry Widget Nu2Python 6 3,074 Oct-21-2021, 03:01 PM
Last Post: Nu2Python
  method to add entries in multi columns entry frames in self widget sudeshna24 2 2,309 Feb-19-2021, 05:24 PM
Last Post: BashBedlam
  [Tkinter] Trouble getting data from an entry. Oshadha 2 2,521 Feb-05-2021, 03:35 AM
Last Post: steve_shambles
  Entry Widget issue PA3040 16 6,999 Jan-20-2021, 02:21 PM
Last Post: pitterbrayn
  [Tkinter] password with Entry widget TAREKYANGUI 9 6,111 Sep-24-2020, 05:27 PM
Last Post: TAREKYANGUI
  [Tkinter] Get the last entry in my text widget Pedroski55 3 6,492 Jul-13-2020, 10:34 PM
Last Post: Pedroski55
  How to retreive the grid location of an Entry widget kenwatts275 7 4,740 Apr-24-2020, 11:39 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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