Python 3 Tkinter 启动画面 [英] Python 3 Tkinter Splashscreen
问题描述
我一直想在主程序出现之前添加一个显示为启动画面的图像,但我无法让它工作.
I've been wanting to add an image displayed as a Splash Screen before the main program shows up, but I can't get it to work.
我希望图像在显示器中居中,并且只显示图像而不显示其他内容.
I want the image to be centered in the monitor and ONLY show the image and nothing else.
我的代码是这样的:
root = tk.Tk()
root.overrideredirect(True)
width = root.winfo_screenwidth()
height = root.winfo_screenheight()
root.geometry('%dx%d+%d+%d' % (width*0.8, height*0.8, width*0.1,
height*0.1))
image_file = "Flexbase.png"
image = tk.PhotoImage(file=image_file)
canvas = tk.Canvas(root, height=height*0.8, width=width*0.8, bg="brown")
canvas.create_image(width*0.8/2, height*0.8/2, image=image)
canvas.pack()
root.after(5000, root.destroy)
root.mainloop()
我做错了什么?有人可以向我解释显示图像的工作原理吗?
What am I doing wrong? Can someone explain to me how displaying an image works?
P.S.:如果这些信息有帮助,图片本身是 640x160,没有任何透明内容.
P.S.: If this information will help, the image itself is 640x160 and doesn't have anything transparent.
推荐答案
我带着这个代码的图片:
I bring the image with this code:
arrow = ImageTk.PhotoImage(Image.open("go-next.png"))
注意,您也可以使用此删除标题栏
As a note, you can also remove the title bar with this
root.wm_attributes('-type', 'splash')
它使启动画面看起来更好
It makes the splash screen look much better
这篇关于Python 3 Tkinter 启动画面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!