I'm making a music player GUI and I can't make it appear on the taskbar or in Alt-Tab. I have set overrideredirect() to true to remove the borders and the title. I also made it so that when the user does a 'mouse click and drag' action the window moves.
Here's the code:
import tkinter
import sys
import os
class Win(tkinter.Tk):
global imgfile
imgfile = r"play.png"
def __init__(self, master=None):
def close():
self.destroy()
sys.exit()
def dirchosen():
global songlist
songlist = []
try:
os.chdir(dirinput.get())
except:
print("Invalid Directory")
raise
for file in os.listdir(dirinput.get()):
songlist.append(file)
tkinter.Tk.__init__(self, master)
self.overrideredirect(True)
self._offsetx = 0
self._offsety = 0
self.bind('<Button-1>', self.clickwin)
self.bind('<B1-Motion>', self.dragwin)
self.geometry("350x200")
self.config(bg="#FF4766")
titlelabel = tkinter.Label(self, text="FoxSGR Media Player", bg="#FF4766", font=("Segoe UI", 12))
titlelabel.pack(ipady=4)
chdirbutton = tkinter.Button(self, relief="groo", activebackground="#FF8080", command=dirchosen)
chdirbutton.config(text="Choose Directory", bg="#FF4766", font=("Segoe UI", 8))
chdirbutton.pack()
chdirbutton.place(relx=0.66, rely=0.22)
dirinput = tkinter.Entry(self, font=("Segoe UI", 8), width="34")
dirinput.pack()
dirinput.place(relx=0.05, rely=0.23)
xbutton = tkinter.Button(self, text="x", height="1", command=close)
xbutton.config(bg="red", activebackground="#FF8080", relief="groo", font=("Segoe UI", 8))
xbutton.pack()
xbutton.place(relx=0.90, rely=0.05)
def dragwin(self, event):
x = self.winfo_pointerx() - self._offsetx
y = self.winfo_pointery() - self._offsety
self.geometry('+{x}+{y}'.format(x=x, y=y))
def clickwin(self, event):
self._offsetx = event.x
self._offsety = event.y
win = Win()
# Had to set the images appart from up there
imgplay = tkinter.PhotoImage(file=imgfile)
playbutton = tkinter.Button(win, image=imgplay, bg="#FF4766", relief="flat")
playbutton.pack()
playbutton.place(rely=0.45, relx=0.4)
imgnext = tkinter.PhotoImage(file="next.png")
nextbutton = tkinter.Button(win, image=imgnext, bg="#FF4766", relief="flat")
nextbutton.pack()
nextbutton.place(rely=0.45, relx=0.57)
imgprev = tkinter.PhotoImage(file="previous.png")
prevbutton = tkinter.Button(win, image=imgprev, bg="#FF4766", relief="flat")
prevbutton.pack()
prevbutton.place(rely=0.45, relx=0.30)
win.mainloop()
Is there any way that I can make it at least appear in Alt-Tab?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…