Two naive Tkinter questions

Andrew Koenig ark at
Sun Nov 2 21:10:55 CET 2003

from Tkinter import *

class Application(Frame):

    def setcolor(self):
        self["bg"] = "blue"

    def createWidgets(self):
        self.b1 = Button(self, bg = "red", command = self.setcolor) = 50, width = 50)

        self.b2 = Button(self, text = "Exit", command = self.quit) = 50, width = 50, x = 50)

    def __init__(self, master=None):
        Frame.__init__(self, master) = 50, width = 100)

app = Application()

1) When I run this program, it displays two buttons.  When I click the
button on the left, I would like the color of that button to change from red
to blue.  This code is obviously the wrong way to accomplish this, because
when setcolor is called, it gets the button's parent, not the button itself.
How do I arrange for setcolor to get the right object?

2) The window in which these buttons appear is the wrong size, and does not
depend on the height and width given to in __init__.  Yet the
height and width arguments do something, because if I set width to 75, it
cuts off half the right-hand button.  How do I say how large I want the
window to be?

More information about the Python-list mailing list