LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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-04-2008, 07:05 PM   #1
raskol
Member
 
Registered: Mar 2008
Posts: 51

Rep: Reputation: 15
Tkinter-GUI: how to make btuttons the same size?


Buttons shrink to fit the symbol/text u put on it. well i dont want that it looks ugly. how do i set the same size for all the buttons?
i thought it was row/columnspan at first but it doesnt seem to work.

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("Calculator")
        
        """Display the main window"
        with a little bit of padding"""
        self.grid(padx=10,pady=10)
        self.CreateWidgets()
       
    def CreateWidgets(self):

        self.btnDisplay = Button(self, text="1", state=DISABLED)
        self.btnDisplay.grid(row=0, column=0, padx=5, pady=5)

        self.btnDisplay = Button(self, text="2", state=DISABLED)
        self.btnDisplay.grid(row=0, column=1, padx=5, pady=5)

        self.btnDisplay = Button(self, text="3", state=DISABLED)
        self.btnDisplay.grid(row=0, column=2, padx=5, pady=5)

        self.btnDisplay = Button(self, text="+", state=DISABLED)
        self.btnDisplay.grid(row=0, column=3, padx=5, pady=5)

        self.btnDisplay = Button(self, text="4", state=DISABLED)
        self.btnDisplay.grid(row=1, column=0, padx=5, pady=5)

        self.btnDisplay = Button(self, text="5", state=DISABLED)
        self.btnDisplay.grid(row=1, column=1, padx=5, pady=5)

        self.btnDisplay = Button(self, text="6", state=DISABLED)
        self.btnDisplay.grid(row=1, column=2, padx=5, pady=5)

        self.btnDisplay = Button(self, text="-", state=DISABLED)
        self.btnDisplay.grid(row=1, column=3, padx=5, pady=5)

        self.btnDisplay = Button(self, text="7", state=DISABLED)
        self.btnDisplay.grid(row=2, column=0, padx=5, pady=5)

        self.btnDisplay = Button(self, text="8", state=DISABLED)
        self.btnDisplay.grid(row=2, column=1, padx=5, pady=5)

        self.btnDisplay = Button(self, text="9", state=DISABLED)
        self.btnDisplay.grid(row=2, column=2, padx=5, pady=5)

        self.btnDisplay = Button(self, text="*", state=DISABLED)
        self.btnDisplay.grid(row=2, column=3, padx=5, pady=5)

        self.btnDisplay = Button(self, text="0", state=DISABLED)
        self.btnDisplay.grid(row=3, column=0, padx=5, pady=5)

        self.btnDisplay = Button(self, text="C", state=DISABLED)
        self.btnDisplay.grid(row=3, column=1, padx=5, pady=5)

        self.btnDisplay = Button(self, text="r", state=DISABLED)
        self.btnDisplay.grid(row=3, column=2, padx=5, pady=5)        

        self.btnDisplay = Button(self, text="/", state=DISABLED)
        self.btnDisplay.grid(row=3, column=3, padx=5, pady=5)        
        
    #def Display(self):
        
                
if __name__ == "__main__":
    guiFrame = GUIFramework()
    guiFrame.mainloop()
 
Old 04-06-2008, 11:04 AM   #2
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
I have used Tcl/Tk, so I am not sure this applies to your Tk environment as well.

You can stretch widgets to have them fit in a grid, using the sticky attribute. You can specify where you want your widget to stick to, and 'we' (west east) should make it stick to both sides of the grid.

In short, define a grid, and place your buttons inside the grid and make them stick to both the right and left side.

jlinkels
 
  


Reply



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
any ideas to reduce log file size or make log file size managed? George2 Programming 2 08-13-2006 06:55 AM
Tkinter cammet Fedora 4 01-21-2006 05:50 PM
Changing my GUI and screen size sh4d0w331 Slackware - Installation 3 12-25-2004 10:33 PM
Python and Tkinter 1337 Twinkie Fedora 2 08-03-2004 11:35 AM
smallest possible installation size with gui? pravoslavnie Fedora 3 12-13-2003 11:59 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:52 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration