How to fit button's size in Tkinter?

Viewed 7279

I have been working with python for a week and with Tkinter even less, so sorry if my question will be typical.


I want to write a simple GUI for an oscilloscope. And I have encountered a problem with how to fit button's size to size of other buttons. Here is what I have reached to (screenshot). enter image description here You might notice that size of trigger and horizontal buttons are less than all channel group. So how to fit their size exactly to channel group size. Here is a piece of my code.

class StartPage(tk.Frame):

def __init__(self, parent, controller):
    tk.Frame.__init__(self, parent)
    self.controller = controller
    startLabel = tk.Label(self,
                          text="Start page")
    startLabel.pack(side="top")

    quitGroup = tk.Frame(self)
    quitGroup.pack(side="bottom")
    quitButton = tk.Button(quitGroup, text="Quit",
                           command=quit,
                           bg="pink")
    quitButton.grid(pady=10)

    channelGroup = tk.Frame(self)
    channelGroup.pack(side=tk.LEFT)
    chLabel = tk.Label(channelGroup,
                       text="Channel group")
    chLabel.grid(pady=10)

    ch1Button = tk.Button(channelGroup, text="CH1 Settings",
                          command=lambda: controller.show_frame("CH1"))
    ch1Button.grid(row=1, column=0)

    ch2Button = tk.Button(channelGroup, text="CH2 Settings",
                          command=lambda: controller.show_frame("CH2"))
    ch2Button.grid(row=2, column=0)

    ch3Button = tk.Button(channelGroup, text="CH3 Settings",
                          command=lambda: controller.show_frame("CH3"))

    ch3Button.grid(row=3, column=0)

    ch4Button = tk.Button(channelGroup, text="CH4 Settings",
                          command=lambda: controller.show_frame("CH4"))
    ch4Button.grid(row=4, column=0)

    triggerGroup = tk.Frame(self)
    triggerGroup.pack(side=tk.LEFT)
    trigLabel = tk.Label(triggerGroup,
                          text="Trigger group")
    trigLabel.grid(pady=10)
    trigButton = tk.Button(triggerGroup, text="Trigger Settings",
                           command=lambda: controller.show_frame("Trigger"))
    trigButton.grid(row=1, column=0)
    trigButton.grid(ipady=43)#43? What?

    horizGroup = tk.Frame(self)
    horizGroup.pack(side=tk.LEFT)
    horizLabel = tk.Label(horizGroup,
                          text="Horizontal group")
    horizLabel.grid(pady=10)
    horizButton = tk.Button(horizGroup,
                            text="Horizontal settings",
                            command=lambda: controller.show_frame("Horizontal"))
    horizButton.grid(row=1, column=0)
    horizButton.grid(ipady=43)#you again ...

Is it possible if those buttons are in different frames? I would like leave it so.

2 Answers
Related