Python Forum
[Tkinter] Keypad Not Aligned
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Keypad Not Aligned
#8
Quote:The key pad should disappear after 12 second have passed
Incorrect PIN would do something similar. I have modified the code I posted earlier to destroy the frame after 12 seconds have passed.
import tkinter as tk
from functools import partial

class KeypadTest():
    def __init__(self, master):
        self.master=master
        self.keypad = ['1', '2', '3', '4', '5', '6',
                       '7', '8', '9', '*', '0', '#']
        self.create_buttons()

        self.time_display=tk.IntVar()
        tk.Label(self.master, textvariable=self.time_display,
                 bg="lightsalmon", font=('Verdana', 15)
                 ).grid(row=5, column=0, sticky="nsew")
        self.time_display.set(12)
        self.twelve_seconds(),\

    def callback(self, btn_num):
        print("btn_num=%s [%s] pressed" % (btn_num, self.keypad[btn_num]))

    def create_buttons(self):
        # create and position all buttons with a for-loop
        # r, c used for row, column grid values
        r = 4
        c = 0
        n = 0

        tk.Label(master, text="".join(["This is a really, really, really, ",
                                       "long label which will make this ",
                                       "single column very large"]),
                bg="lightblue").grid(row=0, column=0)

        ## a separate frame for the keys, so the long Label
        ## will not affect these column sizes
        self.fr=tk.Frame(master, bg="yellow")
        self.fr.grid(row=10, sticky="w")  ## left side

        btn_list=[]
        for label in self.keypad:
            btn_list.append(tk.Button(self.fr, text=label, font='size, 18',
                    width=4, height=1, command=partial(self.callback, n)))
            btn_list[-1].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

    def twelve_seconds(self):
        time_left=self.time_display.get()
        if time_left > 0:
            time_left -= 1
            self.time_display.set(time_left)
            self.master.after(1000, self.twelve_seconds)

        else:
            self.fr.destroy()

master=tk.Tk()
KT=KeypadTest(master)
master.mainloop() 
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,186 Sep-30-2020, 12:19 PM
Last Post: Larz60+
  [Tkinter] Tkinter Entry widget and KeyPad intrgration chiragarya1992 0 7,730 Aug-11-2018, 01:09 AM
Last Post: chiragarya1992
  [Tkinter] enter data with keypad gray 4 7,358 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