LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 04-03-2008, 09:06 PM   #1
raskol
Member
 
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?

Code:
#! /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"""
        Frame.__init__(self,master)
        
        """Set the Window Title"""
        self.master.title("Type Some Text")
        
        """Display the main window"
        with a little bit of padding"""
        self.grid(padx=10,pady=10)
        self.CreateWidgets()
        
    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()
    guiFrame.mainloop()

Last edited by raskol; 04-03-2008 at 09:08 PM.
 
Old 04-06-2008, 04:57 PM   #2
ranger_nemo
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.
 
  


Reply


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 08:43 PM.

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