最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python 3.x - Add entry to tkinter without window border - Stack Overflow

programmeradmin0浏览0评论

I'm creating a borderless window like this

def _create_window(self):
        if self.current_window is not None:
            return
        self.mouse_listener = MouseListener(
            on_left_mouse_click=self.on_left_mouse_pressed,
            on_right_mouse_click=self.on_right_mouse_pressed,
        )

        threading.Thread(
            target=self._run_tkinter_window,
        ).start()

    def _run_tkinter_window(self):
        self.current_window = tk.Tk()
        
        # Make the window borderless
        self.current_window.overrideredirect(True)
        # self.current_window.title("Ctrl + Space Pressed!")

        self.width = 500
        self.height = 50

        if self.config is not None:
            self.width = self.config["window_settings"]["width"]
            self.height = self.config["window_settings"]["height"]

        self.current_window.geometry(f"{self.width}x{self.height}")

        screen_width = self.current_window.winfo_screenwidth()
        screen_height = self.current_window.winfo_screenheight()

        x = (screen_width // 2) - (self.width // 2)
        y = (screen_height // 2) - (self.height // 2)

        self.current_window.attributes("-topmost", True)
        self.current_window.protocol(
            "WM_DELETE_WINDOW",
            self._close_window,
        )

        self.current_window.geometry(
            f"{self.width}x{self.height}+{x}+{y}",
        )

        self.entry = tk.Entry(
            self.current_window,
            font=(
                "Helvetica",
                16,
            ),
        )

        self.entry.pack(expand=True, fill=tk.BOTH)

        # Ensure the Entry widget receives keyboard input correctly
        # self.entry.bind("<FocusIn>", self.on_focus)

        self.current_window.update_idletasks()
        self.current_window.mainloop()

I want to make something like a macos's spotlight search in Ubuntu. But when the window appears the text is entering somewhere in the bottom right corner of the screen.

And if I comment out this line

self.current_window.overrideredirect(True)

it works as expected.

What is the problem with it? Can I somehow get the expected behavior in a chromeless window?

发布评论

评论列表(0)

  1. 暂无评论