简体   繁体   中英

How to make Tkinter window stationary

I was trying to run a Thread for some time.So, if I try to reposition the Tkinter window I get

Fatal Python error: PyEval_RestoreThread: NULL tstate
Python runtime state: initialized

But then I realized if I didn't reposition that window. It was working fine.

Some More Details: To reposition a window, we manually do it by dragging/moving the title bar of the Window Hence Overdirected(True) removes the Title Bar. I want to know if it's possible to have the default Title Bar but it performs the same action as Overdirected(True)

Edit: I wanted to use the same feature as overdirected(True) but I still need the title bar

I tried to search for some pre questions but most of them were based on resizeable things.

One way to do this is by binding the configure event and give a specific position that will be forced by the geometry method of the Toplevel :

import tkinter as tk
    
def stay(event):
    my_spot = 100,100
    root.geometry("+%d+%d" % (my_spot))
    
root=tk.Tk()
root.bind('<Configure>', stay)
    
root.mainloop()

Another way, with addition problems, to solve the problem I to set the overrideredirect flag to True :

import tkinter as tk
    
root=tk.Tk()
root.geometry("+%d+%d" % (100,100))
root.overrideredirect(1)
    
root.mainloop()

Some More Details: To reposition it we manually do it by dragging/moving the title bar of the Window so Overdirected(True) removes the Title Bar So I want to know if it's possible to have the default Title Bar but it doesn't respond to event that can resize the whole window

To achive that, you can use the built-in method resizable :

import tkinter as tk
    
root=tk.Tk()
root.resizable(False, False)
    
root.mainloop()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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