Windows XP 上的 Tkinter 激活窗口 [英] Tkinter activate window on Windows XP

查看:91
本文介绍了Windows XP 上的 Tkinter 激活窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小型 GUI 应用程序,用于侦听网络消息,以便用户可以更新一些信息并接受它.这是在生产工厂环境中,用于与特定的物理硬件进行交互(在某些情况下通过串行).工作流程如下所示:

I have a small GUI application that listens for network messages so a user can update some info and accept it. This is in a production factory environment and used for interacting with a specific piece of physical hardware (over serial in some cases). The workflow looks like this:

  • 用户正在与另一个程序交互(5250 绿屏)
  • 他们输入特定的键绑定,将 UDP 消息发送到 Tkinter GUI
  • Tkinter GUI 执行 deiconify()
  • 用户编辑数据,接受 (Enter) 并执行 iconify()

我的问题是,在 Windows XP 上,当我执行 deiconify 时 GUI 不会变为活动状态,相反在 iconify 时不会回退到先前的窗口.我尝试了一些我在其他问题中找到的东西,例如:

My issue is that on windows XP, the GUI does not become active when I do the deiconify and conversely does not fall back to the prior window on iconify. I have tried some things I found in other questions such as:

  • 将 Tk GUI 设置为顶部.. self.wm_attributes("-topmost", 1)
  • 试图设置/强制焦点... self.focus_set()self.focus_force()

尽管第一个窗口是可见的,但我似乎无法将其设为活动窗口,以便用户无需单击"即可激活它.释放焦点"也是如此,以便活动窗口成为他们之前所在的窗口 (5250).

Although the window is visible with the first, I can not seem to get it to be the active window so that the user can type in it without "clicking" on it to activate. The same is true for releasing the "focus" so that the active window becomes the one they were previously on (5250).

这似乎是其他人也遇到的问题,但我找不到任何有效的方法.有没有一种编程方式来激活窗口并在完成后释放它?

It seems like an issue that others also have had but I have not been able to find anything that works. Is there a programmatic way to get the window activated and release it when done?

推荐答案

不幸的是,一周后没有答案,我无法找到使用 Tkinter 执行此操作的直接方法.不过,我确实找到了解决问题的方法,并且它似乎始终如一地工作.以下是我激活屏幕所采取的步骤:

Unfortunately, after a week there have been no answers and I was not able to find a direct way to do this with Tkinter. I did find a way to solve the problem though and it appears to work consistently. Here are the steps I took to make the screens activate:

  • 安装 pywin32.
  • 创建一个函数来激活 tk 应用程序.
  • 创建一个激活 5250 的函数.

然后,每次我执行图标化/去图标化时,我也会运行该功能来激活相应的屏幕.激活 tk 窗口的代码如下所示:

Then each time I do a iconify/deiconify I also run the function to activate the appropriate screen. The code that activates the tk window looks like this:

def activate_self(self):
    """ Activate this window. """
    shell = win32com.client.Dispatch('WScript.Shell')
    shell.AppActivate(str(self.title))
    shell = None

激活调用者的代码有点难看,因为它必须猜测标题,但都是相同的基本概念.

The code that activates the caller is a little ugly since it has to guess the title but is the same basic concept.

这篇关于Windows XP 上的 Tkinter 激活窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆