我正在尝试创建一个slasph屏幕,它在tkinter和python 3的菜单栏上兼具关于屏幕的功能。
到目前为止,我已经读到,我应该在第二个splash_root上使用Toplevel()方法,但它只是发送给我一个错误,name 'Toplevel' is not defined。
我是不是遗漏了一些基本的东西,或者只是误解了Toplevel()的工作原理?
import tkinter as tk
import tkinter.ttk as ttk
from PIL import ImageTk, Image
from ttkthemes import ThemedTk
def splash_screen():
splash_root = Toplevel(root)
splash_root.geometry("500x400")
img_title = ImageTk.PhotoImage(Image.open("art/icons/random.png"))
lbl_img_title = ttk.Label(splash_root,image=img_title)
lbl_img_title.pack(side="top",pady=20)
splash_label_by = ttk.Label(splash_root, text="name")
splash_button = ttk.Button(splash_root, text="close", command=lambda: splash_root.destroy())
splash_label_by.pack(pady=20, padx=20)
splash_button.pack(ipadx=10, ipady=10)
splash_screen()
root = ThemedTk(themebg=True)
root.set_theme('black')
root.title("splash")
root.geometry("500x500")
root.mainloop()发布于 2021-05-31 19:40:32
你的问题的答案是:
#Toplevel(root) is not defined
tk.Toplevel(root) #will solve your Toplevel problem.如果在声明根之前调用splash_screen(),将不会定义根,并且您的代码仍然不能工作。
https://stackoverflow.com/questions/67772716
复制相似问题