Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making Tkinter windows show up in the taskbar

I want a program of mine to show up in the taskbar, but still not have the traditional windows boarder. How can I go about this? I know of self.overrideredirect(1), however this removes my program from the taskbar.

This is for Windows 7.

like image 657
rectangletangle Avatar asked Nov 01 '10 01:11

rectangletangle


People also ask

How do I use multiple windows in tkinter?

First, define a class Window that inherits from the Toplevel window. The Window will be closed once the Close button is clicked. Third, in the open_window() method, create a new instance of the Window and call the grab_set() method so that it can receive events.

How do I close a tkinter window without destroying it?

In order to destroy the window we can use the destroy() callable method. However, to hide the Tkinter window, we generally use the “withdraw” method that can be invoked on the root window or the main window. In this example, we have created a text widget and a button “Quit” that will close the root window immediately.

What is a root window in tkinter?

According to the conventions, the root window in Tkinter is usually called "root", but you are free to call it by any other name. The third line executed the mainloop (that is, the event loop) method of the root object. The mainloop method is what keeps the root window visible.


2 Answers

I make no claim about this being the 'correct' way to do it, but see if this works for you:

try:
    from tkinter import *
except ImportError:
    from Tkinter import *


class NewRoot(Tk):    
    def __init__(self):
        Tk.__init__(self)
        self.attributes('-alpha', 0.0)

class MyMain(Toplevel):
    def __init__(self, master):
        Toplevel.__init__(self, master)
        self.overrideredirect(1)
        self.attributes('-topmost', 1)
        self.geometry('+100+100')
        self.bind('<ButtonRelease-3>', self.on_close)  #right-click to get out

    def on_close(self, event):
        self.master.destroy()


if __name__ == '__main__':

    root = NewRoot()
    root.lower()
    root.iconify()
    root.title('Spam 2.0')

    app = MyMain(root)
    app.mainloop()
like image 56
noob oddy Avatar answered Oct 26 '22 13:10

noob oddy


You could add a toplevel window under the root object, make root invisible and then handle the icon events to hide or show the toplevel window.

root = tkinter.Tk()
top = tkinter.Toplevel(root)
top.overrideredirect(1) #removes border but undesirably from taskbar too (usually for non toplevel windows)
root.attributes("-alpha",0.0)

#toplevel follows root taskbar events (minimize, restore)
def onRootIconify(event): top.withdraw()
root.bind("<Unmap>", onRootIconify)
def onRootDeiconify(event): top.deiconify()
root.bind("<Map>", onRootDeiconify)

window = tkinter.Frame(master=top)
window.mainloop()
like image 42
shuji Avatar answered Oct 26 '22 14:10

shuji