Anjali
Anjali

Reputation: 506

Mysterious extra space after buttons in tkinter

I'm running tkinter on Python3.4 on Windows and I want two buttons in my GUI box. I'm following [this link]

The code is this:

import tkinter as tk

class App(tk.Tk):
    def __init__(self):
        tk.Tk.__init__(self)
        self.initialize()

    def initialize(self):
        button_crop = tk.Button(self, text=u"Crop", command=self.OnCrop)
        button_crop.pack(side="left")

        button_reset = tk.Button(self, text=u"Reset", command=self.OnReset)
        button_reset.pack(side="left")

    def OnCrop(self):
        pass

    def OnReset(self):
        pass

app = App()

app.mainloop() 

Now I get a button which has some extra space to the right

enter image description here

I've tried initialising a grid() and then button_crop.grid(column=0, row=1) but I get the same result.

Please help me remove this extra blank space to the right.

Upvotes: 0

Views: 318

Answers (1)

ventik
ventik

Reputation: 887

Do you want this behaviour?

import tkinter as tk

class App(tk.Tk):
    def __init__(self):
        tk.Tk.__init__(self)
        self.initialize()

    def initialize(self):        

        button_crop = tk.Button(self, text=u"Crop", command=self.OnCrop)
        button_crop.grid(row=0, column=0, sticky=(tk.N, tk.S, tk.E, tk.W))

        button_crop = tk.Button(self, text=u"Reset", command=self.OnReset)
        button_crop.grid(row=0, column=1, sticky=(tk.N, tk.S, tk.E, tk.W))

        for i in range(2):
            self.columnconfigure(i, weight=1)

        self.rowconfigure(0, weight=1)

    def OnCrop(self):
        pass

    def OnReset(self):
        pass

app = App()

app.mainloop() 

Upvotes: 1

Related Questions