How to remove just the window border?

久未见 提交于 2019-12-29 08:02:15

问题


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?


回答1:


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




回答2:


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()


来源:https://stackoverflow.com/questions/31085533/how-to-remove-just-the-window-border

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!