python - Toggle tkinter window visibility
问题描述
I'm trying to toggle tkinter window visibility when I click p
.
toggle = True
if keyboard.is_pressed('p'):
toggle = not toggle
if toggle:
app.wm_attributes("-alpha", 0)
else:
app.wm_attributes("-alpha", 1)
解决方案
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:
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()
Also keep a note that wm_attributes()
and attributes()
are the same.
推荐阅读
- linux - 如何根据ips、domain和url过滤apache访问日志?
- python - 使用 Pandas-Datareader 为 Yahoo 导入时收到“未来警告”
- flutter - Flutter dio 图像上传不工作引发服务器 500 错误,但在邮递员中工作
- android - 工具栏盲片
- linux - Kubernetes cron 作业提前 1 分钟运行
- r - 使用 ggplot 根据第一个数据点的所有结果绘制图表
- xml - Android Studio - 按钮 XML 设计
- driver - 点击 Win32 适配器安装失败
- delphi - 如何在 Delphi 中调试 CEF3 / libcef.dll 并收集有关 c0000005 / 001dea9b 异常的信息
- ios - 如何获取稍后将存储在 Realm 表中的 JSON 数组?