Need help with Tkinter

rodzilla2000 at my-deja.com rodzilla2000 at my-deja.com
Mon Dec 13 19:17:16 EST 1999


I'm trying to learn python/Tkinter...

I tried modifying the hello.py script that guido included in the 1.5.2
source.

Here's what I was trying to do (to learn while tinkering...)

Change the "Hello World" button a "Add Exit Button" that would put
another button on the screen to allow exiting the program.

Add the additional exit button...

Here's the code:

=========START OF CODE
# Button test...

import sys
from Tkinter import *

#main routine
def main():
    root=Tk()
    btnAddButton=Button(root)
    btnAddButton['text']='Add Exit Button'
    btnAddButton['command']=subAddButton(root)   # See below
    btnAddButton.pack()

    #start mainloop
    root.mainloop

def subAddButton(parent):
    btnExitButton=Button(parent)
    btnExitButton['text']='Exit Program'
    btnExitButton['command']=subExit   #see below
    btnExitButton.pack()

def subExit():
    sys.exit(0)


#execute the main routine
main()
==========END OF CODE

When I run this code, the exit button is already displayed.  The "Add
Exit Button" button seems to do nothing, I would have thought it would
keep adding more exit buttons...


I ran the code through the debugger and it looks like the "Exit" button
gets drawn even before the "Add Exit Button" button gets drawn...


Cany anybody enlighten me?

Thanx...


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list