Python Forum
[Tkinter] Keypad Not Aligned
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Keypad Not Aligned
#4
Then you are gridding something else that expands these columns.
Quote:put the buttons in a separate frame so you don't have outside widgets that control the size of the buttons

Don't know what the following means. There are only 3 columns on the keypad.
Quote:but there was still spacing in between the 147 Column and the 258 Column.

This code works as expected, which says that the problem is in some other part of your code. And note that this code does not use a class because it is just a small snippet.
    import tkinter as tk
    from functools import partial 

    master=tk.Tk()

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

    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

    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
    fr=tk.Frame(master, bg="yellow")
    fr.grid(row=10, sticky="w")  ## left side

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

    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,196 Sep-30-2020, 12:19 PM
Last Post: Larz60+
  [Tkinter] Tkinter Entry widget and KeyPad intrgration chiragarya1992 0 7,743 Aug-11-2018, 01:09 AM
Last Post: chiragarya1992
  [Tkinter] enter data with keypad gray 4 7,391 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