Python Forum
[Tkinter] Keypad Not Aligned
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Keypad Not Aligned
#1
I'm having a problem with my GUI window not displaying the keypad on my window correctly. I'm sure it has to do with resolution but don't know how to adjust the code to make it work with my resolution of 800x480. I've posted a screenshot of the window with the keypad and the portion of the code that produces the window. Any help would be greatly appreciated.

[Image: MM2FmMnb]

        while True:
            r,w,x = select([dev], [], [])
            for event in dev.read():
                if event.type==1 and event.value==1:
                        if event.code==28:
                            dbConnection = MySQLdb.connect(host=dbHost, user=dbUser, passwd=dbPass, db=dbName)
                            cur = dbConnection.cursor(MySQLdb.cursors.DictCursor)
                            cur.execute("SELECT * FROM access_list WHERE rfid_code = '%s'" % (rfid_presented))
                            
                            if cur.rowcount != 1:
                                self.welcomeLabel.config(text="ACCESS DENIED")
                                
                                # Log access attempt
                                cur.execute("INSERT INTO access_log SET rfid_presented = '%s', rfid_presented_datetime = NOW(), rfid_granted = 0" % (rfid_presented))
                                dbConnection.commit()
                                
                                time.sleep(3)
                                self.welcomeLabel.grid_forget()
                                self.show_idle()
                            else:
                                user_info = cur.fetchone()
                                userPin = user_info['pin']
                                self.welcomeLabel.grid_forget()
                                self.validUser = ttk.Label(self.tk, text="Welcome\n %s!" % (user_info['name']), font='size, 15', justify='center', anchor='center')
                                self.validUser.grid(columnspan=3, sticky=tk.W+tk.E)
                                
                                self.image = tk.PhotoImage(file=user_info['image'] + ".gif")
                                self.photoLabel = ttk.Label(self.tk, image=self.image)
                                self.photoLabel.grid(columnspan=3)
                                
                                self.enterPINlabel = ttk.Label(self.tk, text="Please enter your PIN:", font='size, 18', justify='center', anchor='center')
                                self.enterPINlabel.grid(columnspan=3, sticky=tk.W+tk.E)
                                pin = ''
                                
                                keypad = [
                                                                    '1', '2', '3',
                                    '4', '5', '6',
                                    '7', '8', '9',
                                    '*', '0', '#',
                                ]
                                
                                # create and position all buttons with a for-loop
                                # r, c used for row, column grid values
                                r = 4
                                c = 0
                                n = 0
                                # list(range()) needed for Python3
                                self.btn = list(range(len(keypad)))
                                for label in keypad:
                                    # partial takes care of function and argument
                                    #cmd = partial(click, label)
                                    # create the button
                                    self.btn[n] = tk.Button(self.tk, text=label, font='size, 18', width=4, height=1, command=lambda digitPressed=label:self.codeInput(digitPressed, userPin, user_info['sms_number']))
                                    # position the button
                                    self.btn[n].grid(row=r, column=c, ipadx=10, ipady=10)
                                    # increment button index
                                    n += 1
                                    # update row/column position
                                    c += 1
                                    if c > 2:
                                        c = 0
                                        r += 1

                                
                                # Log access attempt
                                cur.execute("INSERT INTO access_log SET rfid_presented = '%s', rfid_presented_datetime = NOW(), rfid_granted = 1" % (rfid_presented))
                                dbConnection.commit()
                                accessLogId = cur.lastrowid
                                
                                self.PINentrytimeout = threading.Timer(10, self.returnToIdle_fromPINentry)
                                self.PINentrytimeout.start()
                                
                                self.PINenteredtimeout = threading.Timer(5, self.returnToIdle_fromPINentered)
                            
                            rfid_presented = ""
                            dbConnection.close()
                        else:
                            rfid_presented += keys[ event.code ]
Reply


Messages In This Thread
Keypad Not Aligned - by sappc74 - Feb-08-2019, 04:06 PM
RE: Keypad Not Aligned - by woooee - Feb-08-2019, 07:09 PM
RE: Keypad Not Aligned - by sappc74 - Feb-08-2019, 11:55 PM
RE: Keypad Not Aligned - by woooee - Feb-09-2019, 01:29 AM
RE: Keypad Not Aligned - by sappc74 - Feb-09-2019, 02:59 AM
RE: Keypad Not Aligned - by woooee - Feb-09-2019, 03:12 AM
RE: Keypad Not Aligned - by sappc74 - Feb-09-2019, 03:19 AM
RE: Keypad Not Aligned - by woooee - Feb-09-2019, 05:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ON-SCREEN KEYPAD module ATARI_LIVE 1 2,204 Sep-30-2020, 12:19 PM
Last Post: Larz60+
  [Tkinter] Tkinter Entry widget and KeyPad intrgration chiragarya1992 0 7,750 Aug-11-2018, 01:09 AM
Last Post: chiragarya1992
  [Tkinter] enter data with keypad gray 4 7,411 Feb-11-2017, 10:20 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