[Tutor] On a looping input, subsequent inputs are hidden

Alan Gauld alan.gauld at btinternet.com
Tue Jun 11 10:07:11 CEST 2013


On 11/06/13 07:17, Jim Mooney wrote:

> But the Second and subsequent inputs, in Windows, hide the input with
> dots, while the first shows the input, and I can't figure out why.

Neither can I and I don't have Windows to test on.
However there are a couple of things I'd say about the code.

First you are effectively creating an entire Tkinter app
inside popup() each time. That's a pretty heavyweight way
to generate a messagebox. Have you used the Tkinter
standard message dialogs?

 >>> import tkinter as tk
 >>> from tkinter import messagebox as mb
 >>> top = tk.Tk()   # get the framework running
 >>> top.withdraw()  # hide the root window

Now you can create as many message boxes as you need...

 >>> mb.showinfo("Hello", "My message here")
'ok'
 >>> mb.showinfo("Hello", "and another")
'ok'
 >>>

You can wrap the showinfo() calls in a function with your calls to 
winsound if you really want to.

The other thing was the use of // in the path spec. You
don't need that, Windows is quite happy with a single
forward slash. It's only backslashes(\) that need doubling.

Finally, to try to debug your problem somewhat I'd try commenting out 
the winsound stuff and see if that makes a difference. I don't see how 
it would but eliminating anything that might be confusing the issue is 
always a good starting point.

>
> def popup(usermessage):
>      if 'bad' in usermessage:
>          winsound.PlaySound('c://Python33//media//wtf.wav',1)
>      else:
>          winsound.PlaySound('c://Python33//media//goody.wav',1)
>      tk = tkinter.Tk()
>      frame = tkinter.Frame(tk, relief=RIDGE, borderwidth=2)
>      frame.pack(fill=BOTH,expand=1)
>      label = tkinter.Label(frame, text=usermessage)
>      label.pack(fill=X, expand=1)
>      button = tkinter.Button(frame,text="Exit",command=tk.destroy)
>      button.pack(side=BOTTOM)
>      tk.focus_force() #must be here or tkinter window may hide behind
> other windows
>      tk.mainloop()
>
>

HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



More information about the Tutor mailing list