绘制一个覆盖Tkinter中另一个GUI的GUI

时间:2019-05-13 04:11:13

标签: python tkinter tkinter-layout

我正在用Raspberry屏幕编写一个GUI,每次销毁一个GUI并调用一个新的GUI时,都会有大约几秒钟的延迟,以使用户能够看到树莓派的桌面。我想在后台绘制一个加载界面,以便在切换屏幕时用户不会看到树莓派桌面。我使用以下代码:

from tkinter import *

class Load_Screen:

    def __init__(self, master):
        self.master = master
        self.master.configure(background='white')
        self.frame = Frame(self.master)
        self.frame.pack()

        self.canvas = Canvas(self.frame, width = 350, height = 250)
        self.canvas.configure(background='white')
        self.canvas.pack()

        self.img = PhotoImage(file="image/loading.png")
        self.canvas.create_image(55,150, anchor=W, image=self.img)

        newWindow = Toplevel(self.master)
        newWindow.geometry("700x500")
        app = Main_Screen(newWindow)

class Main_Screen:

    def __init__(self, master):
        self.master = master
        self.frame = Frame(self.master)
        self.frame.pack()

def main(): 
    root = Tk()
    root.geometry("760x600")
    app = Load_Screen(root)

    root.mainloop()

if __name__ == '__main__':
    main()

但是,加载屏幕将覆盖主屏幕。我要相反的是底部的加载屏幕和上方的主屏幕

1 个答案:

答案 0 :(得分:1)

这是我在以下位置找到的解决方案 How to make a Tkinter window jump to the front?

from tkinter import *

class Load_Screen:

    def __init__(self, master):
        self.master = master
        self.master.configure(background='white')
        self.frame = Frame(self.master)
        self.frame.pack()

        self.canvas = Canvas(self.frame, width = 350, height = 250)
        self.canvas.configure(background='white')
        self.canvas.pack()

        self.img = PhotoImage(file="image/loading.png")
        self.canvas.create_image(55,150, anchor=W, image=self.img)

        newWindow = Toplevel(self.master)
        newWindow.geometry("700x500")
        app = Main_Screen(newWindow)

class Main_Screen:

    def __init__(self, master):
        self.master = master
        self.frame = Frame(self.master)
        self.frame.pack()

def main(): 
    root = Tk()
    root.geometry("760x600")
    root.lift()
    app = Load_Screen(root)

    root.mainloop()

if __name__ == '__main__':
    main()

使用root.lift()将Load_Screen置于Main_Screen下方