unable to apply a ttk theme to .toplevel()

331 Views Asked by At

I'm trying to rcreate a slasph screen which doubles as an about screen on a menu bar in tkinter and python 3.

so far I've read I should be using a Toplevel() method on the second splash_root but It justs send me the error that, name 'Toplevel' is not defined.

Have I missed something basic here or just misunderstood how Toplevel() works?

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()
1

There are 1 best solutions below

3
On

The answer to your question:

#Toplevel(root) is not defined
tk.Toplevel(root) #will solve your Toplevel problem.

If you call splash_screen() before declaring root, root will be not defined and your code still wont work.