473,500 Members | 1,664 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Making a second window with Tkinter

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.

Jun 2 '06 #1
4 2182
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/
Jun 2 '06 #2
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()

Jun 3 '06 #3
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/
Jun 3 '06 #4
What you said about why my code is wrong is still a bit fuzzy but it
worked!

Jun 3 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3673
by: Fuzzyman | last post by:
I'm having trouble implementing my GUI using Tkinter...... I've been working through the Tkinter tutorials from 'Programming Python' and am generally happy enough with the functionality and feel...
5
1599
by: Peter Moscatt | last post by:
Ok.... I am pretty new to Python (as you may have gathered from previous posts). So now it time for another one of my ridiculous questions.... :-) When using 'Tkinter', what is used as the...
0
1944
by: Richard Townsend | last post by:
I've been experimenting with passing a window handle from a wxPython app to a Tkinter app. The Tkinter app should embed a Toplevel window containing a Canvas widget in the wxPython app's Frame (see...
3
17756
by: Svennglenn | last post by:
Hi I'm creating a program in Tkinter and I would need help to create a "close button" for dialog windows. One of my typical dialog windows look like this: def show_window(self): top =...
0
3562
by: syed_saqib_ali | last post by:
Below is a simple code snippet showing a Tkinter Window bearing a canvas and 2 connected scrollbars (Vertical & Horizontal). Works fine. When you shrink/resize the window the scrollbars adjust...
1
12225
by: syed_saqib_ali | last post by:
Below is a simple code snippet showing a Tkinter Window bearing a canvas and 2 connected scrollbars (Vertical & Horizontal). Works fine. When you shrink/resize the window the scrollbars adjust...
4
6283
by: Claus Tondering | last post by:
I am trying to make a Tkinter main window appear and disappear, but I have problems with that. Here is a small code sample: class MyDialog(Frame): def __init__(self): Frame.__init__(self,...
16
2366
by: Andrea Gavana | last post by:
Hi Diez & All, Do you mind explaining "why" you find it *buttugly*? I am asking just out of curiosity, obviously. I am so biased towards wxPython that I won't make any comment on this thread...
3
2287
by: Dream | last post by:
The code create 2 windows. 2 radiobuttons are put on the second window. A control variable "v" is binded to the 2 widgets. But when I run the code, I found the control variable not binded...
0
7018
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7183
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7235
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6909
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5491
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4923
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4614
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1431
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
675
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.