Making a second window with Tkinter

Rob Williscroft rtw at freenet.co.uk
Sat Jun 3 05:19:07 EDT 2006


greenflame wrote in news:1149305472.893535.67770
@h76g2000cwa.googlegroups.com in comp.lang.python:

> Ok so I played with your script. Here is a script that more closely
> mimics what I would like to do except that the way I make the variable
> deckstr will be different. The only thing I am confused about is that
> it opens the second window in the beginning and when I click on the
> button, it does nothing even after I have closed the other window.
> 
> from Tkinter import *
> from string import join
> 
> root = Tk()
> 
> def showdeck(deck):
>    deckwin = Toplevel()
>    deckstr = join(deck, "\n")
>    Label(deckwin, text=deckstr, justify=LEFT, anchor=W,
> font="Courier").pack(fill=X)
> 
> L = Button(root, text="Show Deck", font="Courier",
> command=showdeck(list('zxcvbnm')))

You made the buttons command option None (which is what 
showdeck() returns), you need to make command a function 
that calls showdeck(list('zxcvbnm')).
 
L = Button(root, text="Show Deck", font="Courier",
command= lambda : showdeck(list('zxcvbnm')))

> L.pack()
> 
> root.mainloop()
> 

lambda's docs online:
http://docs.python.org/ref/lambdas.html

Rob.
-- 
http://www.victim-prime.dsl.pipex.com/



More information about the Python-list mailing list