Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


Search this Thread
Old 04-03-2008, 09:06 PM   #1
Registered: Mar 2008
Posts: 51

Rep: Reputation: 15
Tkinter - why no space between buttons?

using python and Tkinter.

why doesnt this generate any space between the 1 and 4 button and 4and 7 etc?

they are on row 5 and then 7 so shoiuld be some blanks in between.

and how do i make the spac between 1 and2 and 2 and 3 equal?

#! /usr/bin/env python
from Tkinter import *
import tkMessageBox

class GUIFramework(Frame):
    """This is the GUI"""
    def __init__(self,master=None):
        """Initialize yourself"""
        """Initialise the base class"""
        """Set the Window Title"""
        self.master.title("Type Some Text")
        """Display the main window"
        with a little bit of padding"""
    def CreateWidgets(self):
        """Create all the widgets that we need"""
        """Create the Text"""
        self.lbText = Label(self, text="Enter numbers:")
        self.lbText.grid(row=0, column=0)
        """Create the Entry, set it to be a bit wider"""
        self.enText = Entry(self)
        self.enText.grid(row=0, column=1, columnspan=3)
        """Create the Button, set the text and the 
        command that will be called when the button is clicked"""
        self.btnDisplay = Button(self, text="calculate!", command=self.Display)
        self.btnDisplay.grid(row=0, column=4)

        """Create the  "1" Button"""
        self.btnDisplay = Button(self, text="1", command=self.Display)
        self.btnDisplay.grid(row=5, column=0)

        """Create the  "2" Button"""
        self.btnDisplay = Button(self, text="2", command=self.Display)
        self.btnDisplay.grid(row=5, column=1)

        """Create the  "3" Button"""
        self.btnDisplay = Button(self, text="3", command=self.Display)
        self.btnDisplay.grid(row=5, column=2)

        """Create the  "4" Button"""
        self.btnDisplay = Button(self, text="4", command=self.Display)
        self.btnDisplay.grid(row=7, column=0)

        """Create the  "5" Button"""
        self.btnDisplay = Button(self, text="5", command=self.Display)
        self.btnDisplay.grid(row=7, column=1)

        """Create the  "6" Button"""
        self.btnDisplay = Button(self, text="6", command=self.Display)
        self.btnDisplay.grid(row=7, column=2)

        """Create the  "7" Button"""
        self.btnDisplay = Button(self, text="7", command=self.Display)
        self.btnDisplay.grid(row=9, column=0)

        """Create the  "8" Button"""
        self.btnDisplay = Button(self, text="8", command=self.Display)
        self.btnDisplay.grid(row=9, column=1)

        """Create the  "9" Button"""
        self.btnDisplay = Button(self, text="9", command=self.Display)
        self.btnDisplay.grid(row=9, column=2)

        """Create the  "0" Button"""
        self.btnDisplay = Button(self, text="0", command=self.Display)
        self.btnDisplay.grid(row=11, column=0)
    def Display(self):
        """Called when btnDisplay is clicked, displays the contents of self.enText"""
        #tkMessageBox.showinfo("Text", "You typed: %s" % self.enText.get())
##        self.lbText = Label(self, text=self.enText.get())
##        self.lbText.grid(row=1, column=2)

if __name__ == "__main__":
    guiFrame = GUIFramework()

Last edited by raskol; 04-03-2008 at 09:08 PM.
Old 04-06-2008, 04:57 PM   #2
Senior Member
Registered: Feb 2003
Location: N'rn WI -- USA
Distribution: Kubuntu 8.04, ClarkConnect 4
Posts: 1,142

Rep: Reputation: 47
Tk sets height / width depending on whatever is in the row / column. If there isn't anything in row 6, it's height is zero, so there won't be any space betwixt rows 5 and 7.

Similarly, the width of column 0 is set by the width of the "Enter numbers:" label.

If you really want to control the spacing of the number buttons, the best way would be to create a couple Frames... One for the Label / Entry / Button, and one for the number buttons. That way, you can exactly control the height / width.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mouse back and forward buttons are interpreted as buttons 2 and 3 (MX610) jot-87 Linux - Hardware 1 08-06-2007 11:12 AM
Tkinter cammet Fedora 4 01-21-2006 05:50 PM
Python and Tkinter 1337 Twinkie Fedora 2 08-03-2004 11:35 AM
Python: Tkinter. Chu Programming 0 11-10-2003 01:56 AM

All times are GMT -5. The time now is 05:42 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration