使用多个Windows时,Zelle Graphics键盘输入失败

发布于 2025-02-08 17:25:03 字数 1151 浏览 1 评论 0原文

使用多个窗口时,Zelle图形似乎有一个键盘输入问题。鼠标操作正常,但不能进行键盘操作。

看来,当打开第二个窗口时,第一个窗口的键盘输入转移到与第二个窗口关联的对象。然后,如果关闭第二个窗口,则丢失了所有键盘输入。

在接收到每个键的情况下,在窗口1下方的测试中打印了输入。当 w 击中第二个窗口时。在窗口2中输入显示在控制台上。但是,突出显示窗口1,输入的任何字符都以窗口2的字符出现,并且出现了控制台显示“窗口2:和字符”。因此,当窗口2出现时,窗口1上的键盘输入将停止。窗口1的checkKey只是不断返回一个零长度字符串,显示未接收的输入。当 c 输入窗口2时,2关闭,并且从那时起就没有键盘输入作品。窗口1不再接收字符。

在Python版本3.6下,在两台不同的Windows 7计算机上进行了尝试。

鼠标操作正常工作,为正确的窗口对象提供鼠标输入,而不是键盘输入。

有人知道解决这个问题吗?

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文