0

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.

Rahul A Ranger
  • 496
  • 1
  • 5
  • 13

1 Answers1

1

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()
t0mas
  • 127
  • 14
Thingamabobs
  • 7,274
  • 5
  • 21
  • 54
  • The first one worked according to the title but it calls `Configure` twice (Mouse drag event and for restoring it) so that thread problem still exists but `Overdirected` works as expected but again it doesn't allow me to use the Title bar. So I just need to unbind the event that causes the window to resize – Rahul A Ranger Nov 08 '20 at 10:57
  • @RahulARanger can you give me some more informations? Im confused right now. What is the exact problem over there? – Thingamabobs Nov 08 '20 at 11:04
  • sorry for providing less info. I edited the Question. Please Check. Repositioning can freeze an app when the app has some 5-6 active threads or at least two threads performing heavy tasks. So I want to customize the Overdirected(True) without losing the default title bar – Rahul A Ranger Nov 08 '20 at 11:13
  • I updated as well. Is this what you want to achive? – Thingamabobs Nov 08 '20 at 11:15
  • I assume you are new to `tkinter` I had provide a small overview of the geometry managment of tkinter [here](https://stackoverflow.com/questions/63536505/how-do-i-organize-my-tkinter-appllication/63536506#63536506) – Thingamabobs Nov 08 '20 at 11:19
  • It's Not size-based tho. It's ok, I will use a customized title bar along with `Overdirected(True) `. – Rahul A Ranger Nov 08 '20 at 11:27
  • 1
    May I can give you a hint there, [how to resize after overrideredirect](https://stackoverflow.com/a/64077176/13629335) – Thingamabobs Nov 08 '20 at 11:29