Skip to content Skip to sidebar Skip to footer

Python Tkinter Hide And Show Window Via Hotkeys

I'm trying to write a program that I can hide and show via hotkeys. I managed to get the application to show and hide using the library 'keyboard', however due to the 'wait' functi

Solution 1:

Just drop this wait command, its an additional mainloop, which is not needed as Tkinter does its job. I tried to fix your problem with threading, but as I wanted to check exactly what is NOT working, I accidentially made what I suppose you wanted to. So the Code is:

import tkinter as tk
import keyboard

classApp(tk.Tk):

    def__init__(self):
        super().__init__()
        self.geometry("800x600")
        self.title("Main frame")

        self.editor = Tk.Text(self)
        self.editor.pack()
        self.editor.config(font="Courier 12")
        self.editor.focus_set()


        keyboard.add_hotkey('ctrl+alt+s', self.show)
        keyboard.add_hotkey('ctrl+alt+h', self.hide)


    defshow(self):
        self.update()
        self.deiconify()

    defhide(self):
        self.update()
        self.withdraw()


if __name__ == "__main__":
    App().mainloop()

I hope this works for you. I'd also recommend changing this key settings. Testing with those in PyZo is IMPOSSIBLE! It always tries to "save as...", which I don't want to...

Post a Comment for "Python Tkinter Hide And Show Window Via Hotkeys"