0

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.

Anjali
  • 508
  • 6
  • 17
  • Try to remove min and max buttons. It seems that form cannot be less than size of system buttons. Look here https://stackoverflow.com/questions/2969870/removing-minimize-maximize-buttons-in-tkinter – ventik Jul 10 '17 at 06:04
  • @ventik That is not desirable.. I'm ok with increasing the size of the buttons to fit the minimum width. – Anjali Jul 10 '17 at 06:21
  • Do you want the buttons to grow to fill the space, or the window to shrink to remove the extra space? – Bryan Oakley Jul 10 '17 at 12:15

1 Answers1

1

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() 
ventik
  • 877
  • 7
  • 18
  • Can I not just extend size of the "crop" and "reset" buttons till they both just add up to the minimum width? – Anjali Jul 10 '17 at 06:20
  • Yes, this is great! Could you explain what changes in your code helped me get this behaviour? Thanks a ton. – Anjali Jul 10 '17 at 06:47
  • 1
    columnconfigure sets options for some column, weight=1 means that this column will be stretchable. read more here http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/grid-config.html – ventik Jul 10 '17 at 06:50
  • 1
    Thanks @ventik for the help – Anjali Jul 10 '17 at 06:52