当我点击p
时,我试图切换tkinter窗口可见性。
toggle = True
if keyboard.is_pressed('p'):
toggle = not toggle
if toggle:
app.wm_attributes("-alpha", 0)
else:
app.wm_attributes("-alpha", 1)
不确定keyboard
是什么,虽然我正在使用它是keyboard
库。无论如何,您可以使用tkinter
本身。下面是一个示例:
from tkinter import *
app = Tk()
toggle = True # Initially true
def check(e):
global toggle
if toggle: # If true
app.attributes('-alpha',0) # Then hide
toggle = False # Set it to False
else: # If not true
toggle = True
app.attributes('-alpha',1) # Bring it back
app.bind('<p>',check) # Bind to the 'p' key.
app.mainloop()
还要注意wm_attributes()
和attributes()
是相同的。