I’m trying to toggle tkinter window visibility when I click p
.
JavaScript
x
10
10
1
toggle = True
2
3
if keyboard.is_pressed('p'):
4
toggle = not toggle
5
6
if toggle:
7
app.wm_attributes("-alpha", 0)
8
else:
9
app.wm_attributes("-alpha", 1)
10
Advertisement
Answer
Not sure what keyboard
is though I am using it is the keyboard
library. Anyway you can use tkinter
itself for this. Here is an example to set you up:
JavaScript
1
18
18
1
from tkinter import *
2
3
app = Tk()
4
toggle = True # Initially true
5
6
def check(e):
7
global toggle
8
if toggle: # If true
9
app.attributes('-alpha',0) # Then hide
10
toggle = False # Set it to False
11
else: # If not true
12
toggle = True
13
app.attributes('-alpha',1) # Bring it back
14
15
app.bind('<p>',check) # Bind to the 'p' key.
16
17
app.mainloop()
18
Also keep a note that wm_attributes()
and attributes()
are the same.