(Python)不会弹出python中的第二个窗口。在python中打开另一个窗口

时间:2019-10-11 23:35:43

标签: python python-3.x tkinter

我想制作一个恶作剧程序,假装在倒数计时后关闭计算机,该窗口应关闭,另一个窗口应打开,显示消息是恶作剧,并带有一个按钮,如果您单击它,它的功能关闭自身并打开google,但第二个窗口没有打开

from tkinter import *
from time import *
import threading
import webbrowser

def function2():
    webbrowser.open("google.com")
    secondWindow.destroy() 

def after():


    root.destroy()


    secondWindow = Tk()
    secondWindow.title("Prank")
    secondWindow.configure(background="blue")
    secondWindow.geometry("500x300")
    mylabel1 = Label(secondWindow, text="u got pranked", bg="blue")
    mylabel1.pack()
    myphoto = PhotoImage(file="autism.gif")
    mylabel4 = Label(secondWindow, image=myphoto)
    mylabel4.pack()

    mybutton1 = Button(secondWindow, text="Ok", command=function2)
    mybutton1.pack()

    secondWindow.mainloop()


root = Tk()
root.title("Prank")
root.attributes("-fullscreen", True)
root.resizable(False, False)
root.configure(background="red")
root.overrideredirect(True)




def function1():
    mylabel = Label(root, text="", bg="blue")
    mylabel.pack(expand=True)
    mylabel.config(font=("Courier", 35))
    for i in range(4, -1, -1):
        mylabel["text"] = "Shutting down in " + str(i) + " second(s)."
        sleep(1)
        if i == 0:
           after()



thread = threading.Thread(target=function1)
thread.start()


root.mainloop()``

0 个答案:

没有答案
相关问题