-1

I am using Tkinter for Building GUI for my python module but i don't want default windows title bar and border. I used "root.overrideredirect(True)" but with "overrideredirect()" I am losing control from my window like resizing and shifting from one place to another place. When ever I run my GUI its shows on top-left corner of my window.

from Tkinter import *
version = "v0.1"
def getinfo():
        lab1 = Label(fram, text = "Your name :")
        lab2 = Label(fram, text = "Your Password : ")
lab1.grid(row =1,sticky=W)
lab2.grid(row =2,sticky=W)

def Exit():
        sys.exit(1)

def btn2():
        btn_show = Button(fram,text = "Show")
        btn_show.grid(row = 9, sticky = W)
        btn_hide = Button(fram, text = "Hide")
        btn_hide.grid(row = 9,column = 2, sticky = W)

root = Tk()
root.overrideredirect(True)
root.geometry("450x300")
fram = Frame(root)
fram.grid()

default_labels()
btn2()
root.mainloop()
Mike - SMT
  • 14,784
  • 4
  • 35
  • 79
  • Tkinter gets the toolbar and border directly from the OS. Once you remove all this you will need to build some costume borders and write in the behavior you are looking for. – Mike - SMT Jul 25 '18 at 15:14
  • Your code is not a testable bit of code. `default_labels()` refers to nothing. – Mike - SMT Jul 25 '18 at 15:19
  • You can place the window anywhere you want by adding x and y positions to the geometry statement: `root.geometry("450x300+800+50")`. – figbeam Jul 25 '18 at 15:21

2 Answers2

0

Yes, that's exactly what overrideredirect does. You will have to add your own bindings to allow for interactively moving and resizing the window.

The answer to the question Tkinter: windows without title bar but resizable shows how to add resizing.

The answer to the question Python/Tkinter: Mouse drag a window without borders, eg. overridedirect(1) shows how to handle the moving of the window.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
0

Here is a basic example of how you can build your title bar and be able to move your window around. It is not perfect but should serve as a good starting point for your.

import Tkinter as tk


root = tk.Tk()
root.overrideredirect(True)
root.geometry("450x300")
root.config(background="darkblue")
root.columnconfigure(0, weight=1)

def move_event(event):
    root.geometry('+{0}+{1}'.format(event.x_root, event.y_root))

title_frame = tk.Frame(root)
title_frame.grid(row=0, column=0, sticky="ew")
title_frame.columnconfigure(0, weight=1)
title_frame.bind('<B1-Motion>', move_event)

tk.Label(title_frame, text="Custom title bar").grid(row=0, column=0, sticky="w")
tk.Button(title_frame, text="-").grid(row=0, column=1, sticky="e")
tk.Button(title_frame, text="[]").grid(row=0, column=2, sticky="e")
tk.Button(title_frame, text="X", command=root.destroy).grid(row=0, column=3, sticky="e")

tk.Label(root, text="Test window!", fg="white", bg="darkblue").grid(row=1, column=0)

root.mainloop()

Results:

The resulting window can be dragged around though a little bit off as the window will want to move relative to the mouse position.

enter image description here

Mike - SMT
  • 14,784
  • 4
  • 35
  • 79