简体   繁体   English

在 Tkinter Python 中禁用窗口移动

[英]Disable window move in Tkinter Python

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?这是简短的,是否可以在不删除此顶部栏的情况下禁用 Tkinter 窗口的移动?

It would give a minimal and reproducible code, but if it did it would only be two lines, it would be useless.它会给出一个最小的和可重现的代码,但如果它这样做了,它只会是两行,那就没用了。

Bind a event for your window,and set the window .geometry()为您的窗口绑定一个事件,并设置窗口.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()

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,but you will also lose the title bar.您将无法移动 tkinter 窗口,但也会丢失标题栏。 but if you wish to have the title bar, then you can create one by this link .但是如果你想拥有标题栏,那么你可以通过这个链接创建一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM