Last active
January 15, 2024 23:09
-
-
Save CroMarmot/93c0ff9c34bc89b11442c5092d675e9d to your computer and use it in GitHub Desktop.
blackscreen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# apt install python3-tk | |
# pip install screeninfo | |
# not working https://chat.openai.com/share/09bf5a5e-5a24-443c-ad25-a30e09253da4 | |
# https://chat.openai.com/share/bcdf31c6-fffa-43a7-9982-032f415fc016 | |
import sys | |
import tkinter as tk | |
from screeninfo import get_monitors | |
# 获取所有显示器 | |
monitors = get_monitors() | |
print(monitors) | |
num_displays = len(monitors) | |
if num_displays == 1: | |
# 如果只有一个显示器,直接使用该显示器 | |
selected_display = 0 | |
else: | |
# 如果有多个显示器,让用户选择显示器 | |
print("可用的显示器列表:") | |
for i, monitor in enumerate(monitors): | |
print(f"{i + 1}. {monitor.name}") | |
selected_display = None | |
while selected_display is None: | |
try: | |
display_index = int(input("请选择要显示窗口的显示器编号(输入对应数字):")) - 1 | |
if 0 <= display_index < num_displays: | |
selected_display = display_index | |
else: | |
print("无效的选择,请重新输入。") | |
except ValueError: | |
print("无效的输入,请输入一个数字。") | |
def close_app(root): | |
root.destroy() | |
# 选择要在其上显示Tkinter窗口的特定显示器(假设使用第二个显示器) | |
selected_monitor = monitors[selected_display] | |
# 创建主窗口 | |
root = tk.Tk() | |
# 隐藏窗口边框 | |
root.overrideredirect(True) | |
# 设置窗口大小和位置 | |
root.geometry(f"{selected_monitor.width}x{selected_monitor.height}+{selected_monitor.x}+{selected_monitor.y}") | |
# 设置窗口背景颜色为黑色 | |
root.configure(bg="black") | |
# 绑定鼠标点击事件 | |
root.bind("<Button-1>", lambda e: close_app(root)) | |
# 运行主循环 | |
root.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment