主界面
关闭弹窗
贴边效果
贴边可以还原窗口或者关闭程序;
贴边已经默认置顶,方便还原进行操作;
源代码
import os
import sys
import tkinter
from tkinter import *
# 关闭事件
def on_closing():
# 退出程序
def quit():
# 终止程序
os._exit(0)
# # # 退出程序
# 贴边隐藏
def welt():
# 还原窗口
def restore_window():
# 关闭贴边
welt.destroy()
# 调用主函数
main()
# 还原窗口
# 创建贴边窗口
welt = tkinter.Tk()
# 置顶显示
welt.wm_attributes('-topmost',1)
# 禁用改变大小
welt.resizable(width = False, height = False)
# 设置标题
welt.title("贴边隐藏")
# 获取屏幕宽度
screen_width = welt.winfo_screenwidth()
# 获取屏幕高度
screen_height = welt.winfo_screenheight()
# 窗口横向位置
window_position_x = int(screen_width - 80)
# 窗口纵向位置
window_position_y = int((screen_height - 40) / 2)
# 窗口定位
window_positioning = '%dx%d+%d+%d' % (80, 40, window_position_x, window_position_y)
# 设置大小和位置
welt.geometry(window_positioning)
# 关闭弹窗
close.destroy()
# 关闭主窗口
windows.destroy()
# 还原窗口
restore_window_Button = tkinter.Button(welt, text = "还原窗口", command = restore_window)
restore_window_Button.place(x = 0,y = 0, width = 80, height = 40)
# 贴边窗口循环显示
welt.mainloop()
# # # 贴边隐藏
# 创建关闭窗口
close = tkinter.Tk()
# 禁用最大化
close.resizable(False,False)
# 设置标题
close.title("确定要退出吗?")
# 获取屏幕宽度
screen_width = close.winfo_screenwidth()
# 获取屏幕高度
screen_height = close.winfo_screenheight()
# 窗口横向位置
window_position_x = int((screen_width - 300) / 2)
# 窗口纵向位置
window_position_y = int((screen_height - 150) / 2)
# 窗口定位
window_positioning = '%dx%d+%d+%d' % (300, 150, window_position_x, window_position_y)
# 设置大小和位置
close.geometry(window_positioning)
# 退出信息
exit_message_Label = tkinter.Label(close, text = "确定要退出吗?您可以选择:\n[退出]退出程序\n[贴边]贴边隐藏")
exit_message_Label.place(x = 20,y = 20, width = 260, height = 60)
# 退出按钮
quit_Button = tkinter.Button(close, text = "退出", command = quit)
quit_Button.place(x = 30,y = 90, width = 80, height = 30)
# 贴边按钮
welt_Button = tkinter.Button(close, text = "贴边", command = welt)
welt_Button.place(x = 190,y = 90, width = 80, height = 30)
# 关闭窗口循环显示
close.mainloop()
# # # 关闭事件
# 主界面设计
def main():
# 创建主窗口
global windows
windows = tkinter.Tk()
# 禁用最大化
windows.resizable(False,False)
# 设置标题
windows.title("模板")
# 获取屏幕宽度
screen_width = windows.winfo_screenwidth()
# 获取屏幕高度
screen_height = windows.winfo_screenheight()
# 窗口横向位置
window_position_x = int((screen_width - 500) / 2)
# 窗口纵向位置
window_position_y = int((screen_height - 300) / 2)
# 窗口定位
window_positioning = '%dx%d+%d+%d' % (500, 300, window_position_x, window_position_y)
# 设置大小和位置
windows.geometry(window_positioning)
# 窗体关闭监听
windows.protocol("WM_DELETE_WINDOW", on_closing)
# 开发者信息
developer_Label = tkinter.Label(windows, text = "开发者:enter回车键 | 官方下载群:776457443 | 公众号:沧浪一隅")
developer_Label.place(x = 80,y = 270, width = 360, height = 24)
# 主窗口循环显示
windows.mainloop()
# # # 主界面设计
# 程序入口
if __name__ == '__main__':
# 调用主函数
main()
# # # 程序入口