Tkinter在多个屏幕上显示消息

时间:2020-11-04 14:20:10

标签: python tkinter

我正在弄乱Tkinter,并且我想制作一个程序,该程序在上床睡觉时会弹出消息,我已经编写了波纹管,如果从其他文件中调用它会起作用,并显示警告消息晚了。我有多显示器设置,有时会在其他屏幕上错过通知。有没有办法确定我的系统有多少个监视器并在所有监视器上显示相同的消息?

from tkinter import *
from tkinter.ttk import Frame


class App_ui(Frame):
    def __init__(self):
        super().__init__()
        self.ui()

    # Displays warning message
    def ui(self):
        # Starts drawing user interface
        self.master.title("It is night time!")
        self.center_window()
        self.pack(fill=BOTH, expand=1)
        # Place where night start time should be imputed
        frame1 = Frame(self)
        frame1.pack(fill=X)
        msg = "Time to go to bed!"
        label = Label(frame1, text=msg, width=20)
        label.config(font=("Courier", 54))
        label.pack(side=TOP)

    # Class function to center window
    def center_window(self):
        w = 800
        h = 120
        sw = self.master.winfo_screenwidth()
        sh = self.master.winfo_screenheight()
        x = (sw - w) / 2
        y = (sh - h) / 2
        self.master.geometry('%dx%d+%d+%d' % (w, h, x, y))


# Runs interface
def popup():
    warning_msg = Tk()
    warning_msg.wm_attributes("-topmost", 1)
    App_ui()
    warning_msg.after(1500, lambda: warning_msg.destroy())  # Destroy the popup after 1,5 seconds
    warning_msg.mainloop()


if __name__ == '__main__':
    popup()

0 个答案:

没有答案