Why if i create two widgets, it stops working? My main frame loop:
import tkinter as tk
class LobbyGUI(tk.Frame):
def __init__(self):
self.main_window = tk.Tk()
self.x = 200
self.y = 200
self.height = 500
self.width = 900
self.main_window.geometry(f"{self.width}x{self.height}+{self.x}+{self.y}")
super(LobbyGUI, self).__init__(self.main_window)
self.pack()
self.main_window.update_idletasks()
self.widgets = dict()
self.widgets['search'] = SearchWindow(self.main_window)
self.widgets['search2'] = SearchWindow(self.main_window)
self.main_window.bind("<Configure>", self.on_drag)
def mainloop(self, n=0):
while True:
self.update_idletasks()
self.update()
def on_drag(self, event):
for widget in self.widgets.values():
widget.place()
And there is a class supposed to dynamically follow the root window:
class SearchWindow:
def __init__(self, root):
self.root = root
self.top = tk.Toplevel(root)
self.width = 100
self.height = 20
self.top.geometry(f"{self.width}x{self.height}+0+0")
self.place()
self.top.overrideredirect(1) # remove title border
self.entry = tk.Entry(master=self.top, width=self.width, borderwidth=0, highlightthickness=0)
self.entry.pack()
def place(self):
x = self.root.winfo_rootx()
y = self.root.winfo_rooty()
width = self.root.winfo_width()
self.top.geometry(f"+{x + width - self.width - 50}+{y + 20}")
self.top.lift()
It works fine with one SearchWindow
child, but doesnt with two. Where could be an issue with this approach?