python把正在显示的窗口‘1’设置成全屏置顶
Python代码如下:
import tkinter as tk
# 创建主窗口
root = tk.Tk()
# 设置窗口标题
root.title("全屏置顶示例")
# 设置窗口大小
root.geometry("400x300")
# 定义全屏函数
def full_screen():
# 全屏显示
root.attributes('-fullscreen', True)
# 置顶显示
root.attributes('-topmost', True)
# 定义退出全屏函数
def exit_full_screen():
# 退出全屏显示
root.attributes('-fullscreen', False)
# 取消置顶显示
root.attributes('-topmost', False)
# 创建全屏按钮
full_screen_btn = tk.Button(root, text="全屏", command=full_screen)
full_screen_btn.pack(pady=10)
# 创建退出全屏按钮
exit_full_screen_btn = tk.Button(root, text="退出全屏", command=exit_full_screen)
exit_full_screen_btn.pack(pady=10)
# 进入消息循环
root.mainloop()
运行以上代码,点击“全屏”按钮即可将窗口设置为全屏置顶,点击“退出全屏”按钮即可退出全屏模式
原文地址: http://www.cveoy.top/t/topic/hv68 著作权归作者所有。请勿转载和采集!