5

I want to remove window border of my application made using tkinter.

I already used overrideredirect(1), but it didn't satisfy me: it removed the window border as I wanted, but it also removed the icon on the task bar.

How can I just remove the window border?

nbro
  • 15,395
  • 32
  • 113
  • 196
PythonQQ
  • 101
  • 1
  • 2
  • 8

2 Answers2

15

I think this is what you were asking for. I don't know if you can do this without using Toplevel or not, but here's a small example of what you could do to remove the window border and keep the icon in the taskbar.

import tkinter as tk

root = tk.Tk()
root.attributes('-alpha', 0.0) #For icon
#root.lower()
root.iconify()
window = tk.Toplevel(root)
window.geometry("100x100") #Whatever size
window.overrideredirect(1) #Remove border
#window.attributes('-topmost', 1)
#Whatever buttons, etc 
close = tk.Button(window, text = "Close Window", command = lambda: root.destroy())
close.pack(fill = tk.BOTH, expand = 1)
window.mainloop()

You could then add buttons, labels, whatever you want to window

  • Wow! It works, Thank you very much. However, There's a problem that the program is **always on top** when I follow this code. Can you fix this problem? – PythonQQ Jun 27 '15 at 08:06
  • Edited the post should fix your problem. and if it helped would you mind accepting? –  Jun 27 '15 at 08:21
  • Actually this doesn't work for me, on Windows, when I click on the icon in the task bar to minify everything is ok but when I click again to expand the windows doesn't appear on top. – Samuel RIGAUD Jan 30 '20 at 19:55
14

In case you're using a Canvas (because this thread is the first result in Google) and you have those borders annoying you, when you want your canvas to BE the window, the Canvas' constructor has a parameter that should suit your needs : highlightthickness=0

import tkinter as tk

root = tk.Tk()
root.overrideredirect(True)

w, h = 800, 500

canvas = tk.Canvas(root, width=w, height=h, highlightthickness=0)
# ...
# Do your things in your canvas
# ...

canvas.pack(fill='both')

root.mainloop()
bachrc
  • 1,106
  • 1
  • 12
  • 20
  • 1
    How do you create a draggable space in the canvas? – Joe Dec 29 '20 at 09:33
  • You can event listner to an area, and when the area is grabbed, and the the cursor is moving, change the position with `root.geometry` function. – user17517503 May 05 '22 at 20:03