0

我正在构建控制应用程序,阻止用户使用计算机,直到它被操作员解锁。

在锁定期间,操作员可以向用户的计算机发送消息,这些消息通过弹出消息显示给用户。

问题案例:

如果操作员发送两条或更多消息,则仅显示第一条消息,因为我正在使用tkMessageBox.showinfo()它并且它会阻塞,直到用户点击确定按钮。

现在您可能会问为什么我不构建自己的消息框类并让它显示多次而不阻塞?实际上我不能这样做,因为应用程序有focus forcing.

这是应用程序构造函数和focus forcing方法:

def __init__(self):

    self.root_window = Tkinter.Tk()
    self.main_frame = Tkinter.Frame(self.root_window)        

    self.root_window.update_idletasks()
    height = self.root_window.winfo_screenheight()
    width = self.root_window.winfo_screenwidth()
    x = self.root_window.winfo_screenwidth() / 2 - width / 2
    y = self.root_window.winfo_screenheight() / 2 - height / 2
    self.root_window.geometry('{}x{}+{}+{}'.format(width, height, x, y))

    # focus forcing 
    self.root_window.bind("<FocusOut>", self.app_lost_focus)


def app_lost_focus(self, event):
    self.root_window.focus_set()
    self.root_window.after(1, lambda: self.root_window.focus_force())

现在,如果您知道弹出消息的任何其他替代方案,它没有阻止并且可以多次显示[尽管看到了focus forcing],我会很高兴听到它。

4

0 回答 0