0

it seems that I was pending to continue the bombardment of questions. It this is short, Is it possible to disable the movement of the Tkinter window without deleting the top bar of this?

It would give a minimal and reproducible code, but if it did it would only be two lines, it would be useless.

Dante S.
  • 222
  • 3
  • 16
  • Out of curiosity, why do you want to remove the ability of the user to move the window? – Bryan Oakley Mar 13 '20 at 16:46
  • Hello, sorry, I am having problems with my scripts that confuse me and besides it is not easy to deal with the community, so I am somewhat confused. I didn't do it to avoid further confusion, but now I think you need to know. I will create new question to reflect the true situation. – Dante S. Mar 16 '20 at 11:23
  • I am aware that this is not an answer. But I wanted to advise in an hour I will delete this question. It resulted in a disaster. I need to rethink the problems :( – Dante S. Mar 16 '20 at 13:34
  • 1
    Since the question is answered, you are probably not allowed to delete the question. You can ask the person who answered if they would be so kind to remove the answer, so you can delete it, but I would like to ask you to reconsider the deletion. – Dharman Mar 16 '20 at 13:36
  • Oops it happens to me to copy and paste. I just reconsidered. If I can stabilize the problem and ask the right question with the right data, I'm going to link to a new question. I have to abandon the ship sinking and create another one. I don't know what causes the problem and I don't think you can tolerate a code of many lines. – Dante S. Mar 16 '20 at 13:40
  • https://stackoverflow.com/questions/60708583/link-and-unlink-binds-tkinter-python – Dante S. Mar 16 '20 at 15:16
  • nice question XD – Christian May 30 '21 at 18:19

2 Answers2

4

Bind a event for your window,and set the window .geometry()

But now you can not revise the window size by dragging the window's border(But it can maximize the window.).

Here is an example of the code:

import tkinter

def GetWindowPos():
    global X,Y
    X = win.winfo_geometry().split("+")[1]
    Y = win.winfo_geometry().split("+")[2]
    win.bind_all('<Configure>', HoldOn)

def HoldOn(event):
    win.geometry("+{}+{}".format(X,Y))

win = tkinter.Tk()
win.geometry("400x400+{}+{}".format(12,12))
tkinter.Label(win,text="Halo!").grid()
win.after(100,GetWindowPos)

win.mainloop()
jizhihaoSAMA
  • 12,336
  • 9
  • 27
  • 49
  • Hello, sorry, I am having problems with my scripts that confuse me and besides it is not easy to deal with the community, so I am somewhat confused. I didn't do it to avoid further confusion, but now I think you need to know. I will create new question to reflect the true situation. Your code works fine, but unfortunately it doesn't solve my problem. – Dante S. Mar 16 '20 at 11:24
2

I have found a method, but as you might know to achieve something, we have to lose something!

You can use:

root.overrideredirect(True) # turns off title bar

by which you wont be able to move the tkinter window and also Tkinter application won't be displayed in taskbar, but you will also lose the title bar. but if you wish to have the title bar, then you can create one by this link.

Or use below to make a new title bar and also be able to move it(from this answer)

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


# bind title bar motion to the move window function
title_bar.bind('<B1-Motion>', move_window)

But still your Tkinter application won't show up in taskbar, here's a solution(from this answer):

root = tkinter.Tk()
top = tkinter.Toplevel(root)
root.attributes("-alpha",0.0) # to make root invisible

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

You can add a toplevel window under the root object, make toplevel invisible and then handle the icon events of top level to hide or show the root window on taskbar.

Faraaz Kurawle
  • 1,085
  • 6
  • 24