raskol |
04-03-2008 09:06 PM |
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()
|