FAQ
I have a script that will make a window that shows the text I want
using Tkinter. What I need to do is to make another window popup above
the current window showing other text. I tryed:

-----------
from Tkinter imprt *

root = Tk()

L = Label(root, text="Blah")
L.grid(row=0, column=0)

# Other labels are also here but their inclusion is not so relavent.

root.mainloop()

sub = Tk()

subL = Label(root, text="Blah")
subL.grid(row=0, column=0)

sub.mainloop()
----------
However, when I ran the script it only showed the second window after I
closed the first one. After looking at the code I guess I can see why.
The problem is that I do not know how to fix the issue. Thank you for
you help.

Search Discussions

  • James Stroud at Jun 2, 2006 at 9:31 pm

    greenflame wrote:
    I have a script that will make a window that shows the text I want
    using Tkinter. What I need to do is to make another window popup above
    the current window showing other text. I tryed:

    -----------
    from Tkinter imprt *

    root = Tk()

    L = Label(root, text="Blah")
    L.grid(row=0, column=0)

    # Other labels are also here but their inclusion is not so relavent.

    root.mainloop()

    sub = Tk()

    subL = Label(root, text="Blah")
    subL.grid(row=0, column=0)

    sub.mainloop()
    ----------
    However, when I ran the script it only showed the second window after I
    closed the first one. After looking at the code I guess I can see why.
    The problem is that I do not know how to fix the issue. Thank you for
    you help.
    Use Toplevel().

    from Tkinter import *

    root = Tk()

    def callback(e=None):
    t = Toplevel()
    Label(t, text='blah').pack()

    b = Button(root, text='new top', command=callback)
    b.pack()
    root.mainloop()

    Also, do not do this twice in the same script: Tk().

    James

    --
    James Stroud
    UCLA-DOE Institute for Genomics and Proteomics
    Box 951570
    Los Angeles, CA 90095

    http://www.jamesstroud.com/
  • Greenflame at Jun 3, 2006 at 3:31 am
    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')))
    L.pack()

    root.mainloop()
  • Rob Williscroft at Jun 3, 2006 at 9:19 am
    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.
  • Greenflame at Jun 3, 2006 at 9:17 pm
    What you said about why my code is wrong is still a bit fuzzy but it
    worked!

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouppython-list @
categoriespython
postedJun 2, '06 at 9:03p
activeJun 3, '06 at 9:17p
posts5
users3
websitepython.org

People

Translate

site design / logo © 2022 Grokbase