Python Forum

Full Version: Tkinter Entry widget and KeyPad intrgration
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am developing Static IP configuration GUI on ubuntu Linux using Python tkinter.As shown in this IP Configuration GUI figure Where I have two Label and two entry field and two button on root window.And I have a touch keypad on toplevel window.
[Image: 4d0fj.jpg]
I have to do following two tasks so could anyone help me out in below listed features:
  1. Whenever I will click on particular entry field I have to pop up this touch keypad which I developed and have to insert a text on that entry field using that touch keypad.Right now both touch keypad and entry field window appeared together.
  2. I also have to make entry field as shown in below figure. After 3 digits there should be a dot on entry field as like in IP address.
[Image: g3zer.jpg]


from tkinter import *

class Numpad(Frame):
    def __init__(self,root,rownum,colnum):
         Frame.__init__(self,root)
         self.grid(row=int(rownum), column=int(colnum))

    def numpad_create(self):

        btn_list = ['7','8','9','4','5','6','1','2','3','0']
        r = 0
        c = 0
        for b in btn_list:
                self.b = Button(self, text=b, width=3 ,height=3, bg='blue', fg="#FFFFFF", font=('bold',16),
                        activebackground='red', activeforeground="#FFFFFF", command = lambda btn=b:self.digit_action(btn))
                self.b.grid(row=r,column=c)
                c += 1
                if c > 2:
                    c = 0
                    r += 1

        self.b1=Button(self, text='<-', width=3 ,height=3, bg='blue', fg="#FFFFFF", font=('bold',16),
                        activebackground='red', activeforeground="#FFFFFF", command = lambda:self.backspace())
        self.b1.grid(row=3,column=1)
        self.b2=Button(self, text='C', width=3 ,height=3, bg='blue', fg="#FFFFFF", font=('bold',16),
                        activebackground='red', activeforeground="#FFFFFF", command = lambda:self.clear())
        self.b2.grid(row=3,column=2)

    def digit_action(btn):#To pass clicked digits into perticular entry field
        entry1.insert(END,btn)
        entry2.insert(END,btn)
    def backspace():#Delete one digit at a time into perticular entry field
        pass
    def clear():#Clear text in perticular entry field 
        entry1.delete(0,END)
        entry2.delete(0,END)
root = Tk()
root.geometry("300x300")
root.title("Network Configuration")
frame1=Frame(root)
frame1.grid(row=0,column=0)
toplevel=Toplevel(root)
toplevel.title('KeyPad')

ip_label = Label(frame1,text='IP Address: ',width=12,font=("TkTextFont",14),anchor='e')
netmask_label = Label(frame1,text='Netmask: ',width=12,font=("TkTextFont",14),anchor='e')
entry1=Entry(frame1,width=15)
entry2=Entry(frame1,width=15)

save=Button(frame1,text='Save', width=5 ,height=2, bg='blue', fg="#FFFFFF", font=('bold',16),
                        activebackground='red', activeforeground="#FFFFFF", command = lambda:save_action())
cancel=Button(frame1,text='Cancel', width=5 ,height=2, bg='blue', fg="#FFFFFF", font=('bold',16),
                        activebackground='red', activeforeground="#FFFFFF", command = lambda:cancel_action())

def save_action():#to save ip address and netmask for changing system network settings 
pass
def cancel_action():#Cancel configuration page 
root.quit()

#Label,Entry and Button on root window
ip_label.grid(row=0,column=0,pady=5,padx=5)
netmask_label.grid(row=1,column=0,pady=5,padx=5)
entry1.grid(row=0,column=1,pady=5,padx=5)
entry2.grid(row=1,column=1,pady=5,padx=5)
save.grid(row=3,column=0,pady=5,padx=5)
cancel.grid(row=3,column=1,pady=5,padx=5)
#Numpad on Toplevel window
app = Numpad(toplevel,0,0)  
Numpad.numpad_create(toplevel)
root.mainloop()