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

Jim Mooney cybervigilante at gmail.com
Tue Jun 11 08:17:12 CEST 2013


This is puzzling me. I'm inputing an integer, giving a different
visual and audio alert depending if it's bad or good, and that works
fine.  I'm looping input to ask for input again if a noninteger is
entered. That works.

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. I
don't change a thing between the first and subsequent calls to input
except changing the input message to an error message. But it's just
python input, not tkinter. Unless it's a Windows peculiarity. The
input Always shows in DOS. But if it doesn't show in Linux, let's say,
then I would guess it's a Python thing, and maybe there's a switch to
turn that effect off.

============ main program ======================

#Using Python 3.3.2 on Win 7 - jimsbiginteger.py in jimprogs
'''dependencies - pop.py'''

import pop
user_message = 'Type an integer: '

while True:
    try:
        num = int(input(user_message))
        break
    except ValueError:
        user_message = '''
        Sorry,that's not an integer. Try again or Cancel by
        using Cancel in a GUI window, or Ctrl-Z in DOS.
        or Ctrl-C in Linux. One mo try. Type an integer: '''
    except (KeyboardInterrupt, EOFError): #1st Except for GUI, 2nd for
Cmd window
        pop.popup('You cancelled, you so bad!') #string must contain
'bad' to trigger audio
        exit(0)

pop.popup('\n  You printed {}  '.format(num))

============ imported module =======================

#Using Python 3.3.2 on Win 7 - pop.py in jimlib
'''dependencies - winsound, tkinter'''

import winsound
import tkinter
from tkinter.constants import *

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()


-- 
Jim
Today is the day that would have been tomorrow if yesterday was today


More information about the Tutor mailing list