How to run python tkinter application without showing up in units bar or alt-tab

I am working on a countdown timer for Ubuntu using Python and tkinter.
I created most of the parts and now I want my application to be able to run without appearing in the Unity bar or Alt-Tab. Is there any way to do this?

And also I would like if it is possible to create a floating window without a title. I tried it root.overrideredirect(1)

.
But with that, I cannot move the window.

Here is the code for my program.

#!/usr/bin/python3

import tkinter as tk
from tkinter import ttk
from tkinter import TOP,LEFT
import time
import datetime
import sys





class Countdown(ttk.Frame):

    def __init__(self,parent=None, endDate=None):
        ttk.Frame.__init__(self,parent)
        self.style = ttk.Style()
        self.style.theme_use("clam")
        self.pack()
        endDate = endDate.split("/")
        self.endTime = datetime.datetime(int(endDate[2]),int(endDate[1]),int(endDate[0]))
        self.setWidgets()
        self.initWidgets()


    def setWidgets(self):
        self.dLbl = ttk.Label(self,text="0",font="Ubuntu 14 bold")
        self.dLbl.pack(padx=10,pady=10,side=LEFT)
        self.hLbl = ttk.Label(self,text="0",font="Ubuntu 14 bold")
        self.hLbl.pack(padx=10,pady=10,side=LEFT)
        self.mLbl = ttk.Label(self,text="0",font="Ubuntu 14 bold")
        self.mLbl.pack(padx=10,pady=10,side=LEFT)

    def getTimeDelta(self):
        self.curDate = datetime.datetime.now()
        self.diff = self.endTime - self.curDate

        self.tSec = self.diff.total_seconds()
        self.days = self.diff.days
        h = int(((self.tSec) - self.days*24*60*60)/3600)
        self.hours = h if h>0 else 0
        m = int(((self.tSec) - (self.hours*60*60+self.days*24*60*60))/60)
        self.minutes = m if m>0 else 0
        self.sec = int(self.tSec - self.minutes*60)
        return [self.days,self.hours,self.minutes+1]

    def initWidgets(self):
        def set():
            dhm = self.getTimeDelta()
            self.dLbl["text"]=str(dhm[0])+" Days"
            self.hLbl["text"]=str(dhm[1])+" Hours"
            self.mLbl["text"]=str(dhm[2])+" Mins"
            self.after(1000,set)
        set()

root = tk.Tk()
root.title(sys.argv[1])
app = Countdown(root, sys.argv[2])
app.mainloop()

      

+4


source to share


3 answers


To move a window without borders you can take a look at this question for a simple example of how to implement what you want and just keep building on top of it.

For hiding, you can use .iconify()

, in theory minimizing the app in the tray, thereby hiding it, and .deiconify()

for example:



root = tk.Tk()
root.iconify()

      

ps. If this doesn't work on Ubuntu / Unity, you may need to use a different GUI framework to support this behavior on Ubuntu, such as GTK.

0


source


import tkinter    

root = tkinter.Tk()
root.withdraw()
root.mainloop()

      



Will hide the window.

0


source


Make your own titlebar

, like this:

import sys
import tkinter as tk
import tkinter.ttk as ttk
root = tk.Tk() #create the window
titlebar = tk.Label(root,height=2, bg='cyan', fg='navyblue', text=sys.argv[0]) #create the titlebar
resizable = ttk.Sizegrip(root) #make the window resizable
titlebar.pack(fill='both') # display the titlebar
root.overrideredirect(1) #make the window run without appearing in alt tab
#root.withdraw() 
#root.deiconify()
root.geometry('200x200') #set the window size to 200x200
resizable.pack(fill='y',side='right')
def ontitlebarclicked(event):
    global lastposition
    lastposition=[event.x,event.y] 

def ontitlebardragged(event):
    global lastposition
    windowposition=[int(i) for i in root.geometry().split('+')[1:]] # get the window position
    diffposition=[event.x-lastposition[0],event.y-lastposition[1]]
    widthheight=root.geometry().split('+')[0]
    root.geometry(widthheight+'+'+str(windowposition[0]+diffposition[0])+'+'+str(windowposition[1]+diffposition[1]))

titlebar.bind('<Button-1>',ontitlebarclicked)
titlebar.bind('<Button1-Motion>',ontitlebardragged)
titlebar.focus_force()


      

0


source







All Articles