当我启动我的“应用程序”时,它以启动画面中的图片开始,我为菜单屏幕添加了一个测试 png,但它没有打开带有图片的菜单屏幕。我对闪屏使用了相同的代码,但 png 没有显示在菜单中。有谁知道我做错了什么,或者我如何修复不以背景开头的菜单屏幕?提前非常感谢你们!
import tkinter as tk
import random
import time
from PIL import Image, ImageTk
from tkinter.ttk import*
Hoogte = 400
breedte = 400
import tkinter as tk
import time
class Splash(tk.Toplevel):
def __init__(self, parent):
tk.Toplevel.__init__(self, parent)
splashscreenintroplaatje = tk.PhotoImage(file="SvgFileService.png")
splashscreenintroplaatjelabel = tk.Label(self,image=splashscreenintroplaatje)
splashscreenintroplaatjelabel.place(x=0, y=0, relwidth=1, relheight=1)
self.title("Laden...")
self.geometry("358x240")
self.update()
class App(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
self.title("Start Menu")
self.geometry("358x240")
achtergrondmenu = tk.PhotoImage(file="image.png")
achtergrondmenulabel = tk.Label(self, image=achtergrondmenu)
achtergrondmenulabel.place(x=0, y=0, relwidth=1, relheight=1)
#je moet de tk.photoimage weghalen en image png allen als tekst in een tk.photoimage plaatsen
self.withdraw()
splash = Splash(self)
#widget
startknop = tk.Button(self, text="Start App", bg= "#0f8041", fg="black", activebackground="#ce0f25", activeforeground="black", borderwidth=2, relief=tk.SOLID, font="Bahnschrift 10", highlightbackground="red", command= self.destroy)
startknop.grid(row=0, column=3, padx=100)
woordentoevoegenknop = tk.Button(self, text="Woordenlijst aanpassen", bg= "#0f8041", fg="black", activebackground="#ce0f25", activeforeground="black", borderwidth=2, relief=tk.SOLID, font="Bahnschrift 10", highlightbackground="red")
woordentoevoegenknop.grid(row=1, column=3, pady=10, padx=100)
#menu-knoppen
time.sleep(1)
splash.destroy()
self.deiconify()
if __name__ == "__main__":
app = App()
app.mainloop()
def doelwitpress(argumenten):
if argumenten == 1:
var.set('1')
if argumenten == 2:
var.set('2')
if argumenten == 3:
var.set('3')
lbl['text'] = 'Kies uit 1 (kleinst), 2 (kleiner) of 3 (grootsts):'
kleinstedoelwit = ['beneficial', 'eloquent', 'in proximity']
x = random.choice(kleinstedoelwit)
if (var.get() == '1'):
lbl['text'] = x
kleineredoelwit = ['useful', 'advise', 'commence']
y = random.choice(kleineredoelwit)
if (var.get() == "2"):
lbl['text'] = y
grootstedoelwit = ['vehicle', 'combined', 'uproar']
z = random.choice(grootstedoelwit)
if (var.get() == "3"):
lbl['text'] = z
root = tk.Tk()
var = tk.StringVar()
var2 = tk.StringVar()
GrafischeUIcanvas = tk.Canvas(root, height=Hoogte)
GrafischeUIcanvas = tk.Canvas(root, width=breedte)
GrafischeUIcanvas.pack()
achtergrondkleur = tk.Frame(root, bg='#6BAB55')
achtergrondkleur.place(relwidt=1, relheight=1)
kleinstedoelwit = tk.Button(root, text="kleinste doelwit", bg="#0f8041", fg="black", activebackground="#ce0f25", activeforeground="black", borderwidth=2, relief=tk.SOLID, font="Bahnschrift 10", highlightbackground="red", command=lambda: doelwitpress(1))
kleineredoelwit = tk.Button(root, text="kleinere doelwit", bg="#0f8041", fg="black", activebackground="#ce0f25", activeforeground="black", borderwidth=2, relief=tk.SOLID, font="Bahnschrift 10", highlightbackground="red", command=lambda: doelwitpress(2))
grootstedoelwit = tk.Button(root, text="grootste doelwit", bg="#0f8041", fg="black", activebackground="#ce0f25", activeforeground="black", borderwidth=2, relief=tk.SOLID, font="Bahnschrift 10", highlightbackground="red", command=lambda: doelwitpress(3))
kleinstedoelwit.pack(side="left")
kleineredoelwit.pack(side="left")
grootstedoelwit.pack(side="left")
lbl = tk.Label(root, bg='#6BAB55', fg="black")
lbl.place(relx=0.3, rely=0, relwidth=0.45, relheight=0.25)
entry = tk.Entry(root, textvariable=var)
entry.pack(side="top")
entry2 = tk.Entry(root, textvariable=var2, bg="blue")
root.mainloop()