Jay Mosk
Jay Mosk

Reputation: 337

Zelle graphics keyboard input fails when using multiple windows

There seems to be a keyboard input problem with Zelle Graphics when using multiple windows. Mouse operations work fine but not keyboard operations.

It seems that when the 2nd window is opened, keyboard input from the 1st window goes to the object associated with the 2nd window. And then if you close the 2nd window, you have lost all keyboard input.

In the test below window 1's input is printed as each key is received. When a w is hit the 2nd window opens. Typing in window 2 appears on the console. But then highlighting window 1, any characters entered is coming in as characters from window 2, and the console display 'window 2: and the character', appears. So keyboard input on window 1 stops when window 2 comes up. Window 1's checkKey just keeps returning a zero-length string showing no input received. When a c is entered window 2 closes and no keyboard input works from then on. Window 1 no longer receives characters.

This has been tried on two different windows 7 computers under version 3.6 of Python.

Mouse operations work correctly, providing mouse input to the correct window object, but not keyboard input.

Is anyone aware of a fix or a way around this?

from graphics import *

# open window 1
win = GraphWin("window 1",500,500)
win2open = False

while True:
    k = win.checkKey()
    if k != '':
        # display input from window 1
        print ("window 1: ",k)
    if k == 'w':
        # if a 'w' is pressed open window 2 
        win2 = GraphWin("window 2",250,250) 
        win2open = True 
    if win2open == True:    
        m = win2.checkKey()
        if m != '':
          # if windows 2 is open print chars from window 2
            print ('window 2',m)
        if (m == 'c'):
            # if 'c' enterred on window 2 close window 
            win2.close()
            win2open = False

Upvotes: 1

Views: 100

Answers (0)

Related Questions