python tkinter实现侧面弹出窗口,(tkinter侧拉窗口,tkinter滑动窗口),连续多次点击弹窗按钮,重复打开窗口问题

2023-05-16

文章目录

  • 1,效果
  • 2,代码
  • 3,连续多次点击弹窗按钮,重复打开窗口问题

1,效果

2,代码

在这里插入图片描述

from tkinter import *
import time

class FloadWindow(object):
    def __init__(self, shape, locate):
        self.wnd = Tk()
        s_shape = str(shape[0])+'x'+str(shape[1])
        s_locate = '+' + str(locate[0]-shape[0]) + '+' + str(locate[1])
        self.wnd.overrideredirect(True)
        
        path = ['camera_1', 'camera_2', 'camera_3', 'camera_4', 'camera_5', 'camera_6']
        for i in range(len(path)):
            label = Label(self.wnd, text=path[i])
            label.place(x=0,y=i*15+5)

        for width in range(0, shape[0], int(shape[0]/20)):
            time.sleep(0.01)
            self.overturn((width, shape[1]), locate)
    def overturn(self, shape, locate):
        s_shape = str(shape[0])+'x'+str(shape[1])
        s_locate = '+' + str(locate[0]-shape[0]) + '+' + str(locate[1])
        self.wnd.geometry(s_shape + s_locate)
        self.wnd.update()
    def destroy(self, shape, locate):
        for width in range(shape[0], 0, -int(shape[0]/20)):
            time.sleep(0.01)
            self.overturn((width, shape[1]), locate)
        self.wnd.destroy()


class RootWindow(object):
    def __init__(self, shape, locate):
        self.wnd = Tk()
        self.flag = False
        s_shape = str(shape[0])+'x'+str(shape[1])
        s_locate = '+' + str(locate[0]-shape[0]) + '+' + str(locate[1])
        self.wnd.geometry(s_shape + s_locate)
        self.close = False

        button = Button(self.wnd, text='on/off', command=self.fold_on_off)
        button.pack()
    def fold_on_off(self):
        if not self.flag:
            self.flag = True
            self.fload_window = FloadWindow((150, 150),(self.wnd.winfo_x(), self.wnd.winfo_y()))
        else:
            self.fload_window.destroy((150, 150),(self.wnd.winfo_x(), self.wnd.winfo_y()))
            self.flag = False

    def wnd_update(self):
        self.wnd.update()
        if self.flag:
            self.fload_window.overturn((150, 150), (self.wnd.winfo_x(), self.wnd.winfo_y()))

if __name__ == '__main__':
    root = RootWindow((300,200),(500,100))
    while True:
        root.wnd_update()

    root.wnd.mainloop()

3,连续多次点击弹窗按钮,重复打开窗口问题

from tkinter import *
import time
from listdir2 import HbarFrame
import os
from queue import Queue

class FoldWindow(object):
    def __init__(self, shape, locate):
#         self.wnd = Toplevel()
        self.wnd = Tk()
        self.wnd.overrideredirect(True)
        self.overturn((0, shape[1]), locate)
        path = ['camera_1', 'camera_2', 'camera_3', 'camera_4', 'camera_5', 'camera_6']
        for i in range(len(path)):
            label = Label(self.wnd, text=path[i])
            label.place(x=0,y=i*15+5)    
        self.create(shape, locate)

    def overturn(self, shape, locate):
        s_shape = str(shape[0])+'x'+str(shape[1])
        s_locate = '+' + str(locate[0]-shape[0]) + '+' + str(locate[1])
        self.wnd.geometry(s_shape + s_locate)
        self.wnd.update()

    def create(self, shape, locate):
        for width in range(0, shape[0], int(shape[0]/20)):
            self.overturn((width, shape[1]), locate)
            time.sleep(0.01)

    def destroy(self, shape, locate):
        for width in range(shape[0], 0, -int(shape[0]/20)):
            self.overturn((width, shape[1]), locate)
            time.sleep(0.01)
        self.wnd.destroy()

class RootWindow(object):
    def __init__(self, shape, locate):
        self.wnd = Tk()
        self.flag = False
        s_shape = str(shape[0])+'x'+str(shape[1])
        s_locate = '+' + str(locate[0]-shape[0]) + '+' + str(locate[1])
        self.wnd.geometry(s_shape + s_locate)
        self.fold_window_shape = (150,200)
        self.fold_window_list = []

        button = Button(self.wnd, text='on/off', command=self.fold_on_off)
        button.pack()
    def fold_on_off(self):
        if not self.flag:
            if len(self.fold_window_list) == 0:
                self.fold_window = FoldWindow(self.fold_window_shape, 
                                        (self.wnd.winfo_x(), self.wnd.winfo_y()))
                self.fold_window_list.insert(0, self.fold_window)
                while len(self.fold_window_list) > 1:
                    self.fold_window_list.pop().wnd.destroy() 
            self.flag = True
        else:
            if len(self.fold_window_list) > 0:
                self.fold_window_list.pop().destroy(self.fold_window_shape, 
                                    (self.wnd.winfo_x(), self.wnd.winfo_y()))
            self.flag = False

    def wnd_update(self):
        self.wnd.update()
        if self.flag:
            self.fold_window.overturn(self.fold_window_shape, 
                                    (self.wnd.winfo_x(), self.wnd.winfo_y()))

if __name__ == '__main__':
    root = RootWindow((300,200),(500,100))
    while True:
        root.wnd_update()

    root.wnd.mainloop()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

python tkinter实现侧面弹出窗口,(tkinter侧拉窗口,tkinter滑动窗口),连续多次点击弹窗按钮,重复打开窗口问题 的相关文章

  • 用C++打开指定网址

    用C 43 43 打开指定网址原理 system 命令 就像这样 xff1a span class token macro property span class token directive hash span span class t
  • 项目遇到的各种异常抛出及解决方法

    项目遇到的各种异常抛出及解决方法 xff1a 1 java lang NumberFormatException xff1a 类型格式异常 第一次遇到的异常抛出原因及解决方法 xff1a 项目运行没有问题 xff0c 各种接口能正常查询出数
  • 【STC8学习笔记】STC8A8K64S4A12精准延时函数设置

    在设置单片机精准的延时函数的时候 xff0c 给大家一个方法 xff0c STC ISP有一个延时函数计算器 xff0c 可以计算出想要的延时 我的例程也是基于这个软件生成的 xff0c 我生成一个1ms和1us出来 xff0c 剩下的我再
  • vc版本与vs版本对应关系

    vc版本与vs版本对应关系 最近在整理之前代码 xff0c 用cmake编译一直报错 xff0c 忘记了opencv3 1 0不支持vs2019 xff0c 所以在这里总结下vc版本与vs版本对应关系 VC版本号 VS对应版本 vc6 VC
  • cmake编译依赖opencv的c++库

    前面一篇主要讲了c 43 43 项目怎么在本地配置opencv过程 xff0c 这种方式缺点就是只能在开发着本地环境编译 xff0c 换台电脑就会出现环境配置问题 接下来主要讲解 xff0c 使用cmake编译 xff0c 生成一个依赖op
  • c++ stl 迭代器iterators(traits编程技法)

    文章目录 1 1 迭代器设计思维 stl关键所在1 2 迭代器是一种smart pointer1 3 迭代器相应型别 xff08 associated types xff09 1 4 traits编程技法 stl源代码门匙1 4 1 val
  • 如何用算法把一个十进制数转为十六进制数-C语言基础

    这一篇文章要探讨的是 如何用算法实现十进制转十六进制 并不涉及什么特别的知识点 属于C语言基础篇 在翻找素材的时候 xff0c 发现一篇以前写的挺有意思的代码 xff0c 这篇代码里面涉及的知识点没有什么好讲的 xff0c 也没有什么特别的
  • 关于 Qt使用QJsonObject解析失败的问题。

    1 问题 在QJsonObject转 toInt toLongLong 等类型时 xff0c 转换失败 但是转toString xff08 xff09 没有任何问题 列如 xff1a 解决方法 xff1a 这样 xff0c 就可以结局问题
  • char 和 string 的相互转换

    一个char字符转为string span class token keyword char span ch span class token operator 61 span span class token char 39 A 39 s
  • C++STL标准库学习总结/索引/学习建议

    前言 xff1a 如果刚刚开始学习STL标准库 xff0c 不知道从哪里入手学习的话 xff0c 建议去中国大学mooc平台 xff0c 先学习北京大学郭炜老师的 程序设计与算法 xff08 一 xff09 C语言程序设计 xff08 ht
  • Python 调用API接口方式,通过http.client调用api接口,远程调用flask接口方式

    一 创建接口 xff08 如果调用别人的接口 xff0c 跳过此条 xff09 如果没有api xff0c 首先自己写一个接口玩一下 xff1a 必备知识 xff1a 一个项目最基本的文件 xff0c 接口run py文件 config文件
  • git tag和branch的区别

    tag 和branch的区别 Git tag是一系列commit的中的一个点 xff0c 只能查看 xff0c 不能移动 branch是一系列串联的commit的线 git tag的用法 我们常常在代码封板时 使用git 创建一个tag 这
  • 结构体对齐计算(超详细讲解,一看就会)

    想要计算结构体大小 xff0c 咱就先要清楚结构体内存对齐的规则 xff1a 1 结构体的第一个成员直接对齐到相对于结构体变量起始位置为0处偏移 2 从第二个成员开始 xff0c 要对齐到某个 对齐数 的整数倍的偏移处 3 结构体的总大小
  • RTK差分编码

    一 概念 DCB xff08 Differential Code Bias 差分码偏差 xff09 是全球卫星导航系统 xff08 GNSS xff09 中 xff0c 通过不同信号得到的观测值之间存在的系统性偏差 DCB是由卫星和接收机硬
  • 详解JAVA的事件监听机制和观察者设计模式

    一 事件监听机制的三要素 事件源 事件监听器 xff0c 事件对象 监听器一般是JAVA接口 xff0c 用来约定可以执行的操作 二 事件监听机制简要说明 事件源注册一个或者多个事件监听器 xff0c 事件源对象状态发生变化或者被操作时 x
  • Nginx控制IP(段)的访问策略配置

    Nginx engine x 是一个高性能的HTTP和反向代理web服务器 xff0c 同时也提供了IMAP POP3 SMTP服务 有着负载均衡 动静分离等强大的功能 xff0c 而且还有众多三方插件来满足应用要求 这里重点介绍nginx
  • 敏捷开发-互联网时代的软件开发方式

    一 什么是敏捷开发 敏捷开发简单的描述为 xff1a 是一种应对需求快速变化的软件开发方式 敏捷开发的核心思想就是小步快跑 不断迭代 xff0c 在一次次的迭代升级中完成 小目标 最终完成那个 大目标 正因为敏捷开发的这种不断迭代升级的开发
  • Window系统查看端口是否启用以及占用程序

    1 打开DOS命令行窗口 开始 gt 运行 gt cmd xff0c 或者是 window 43 R gt cmd xff0c 调出命令窗口 2 查看当前正在使用的所有端口 命令 xff1a netstat ao 包括协议 xff0c 端口
  • ThreadLocal的深度解读

    一 J2SE的原始描述 This class provides thread local variables These variables differ from their normal counterparts in that eac
  • 消息中间件如何保证消息不丢失

    一 消息队列MQ的三个阶段 1 生产者发送消息到MQ 2 MQ存储消息到内存或者硬盘 3 消费者消费消息 由于网络的原因 服务器的原因 程序的原因等等 xff0c 在每个阶段都有可能引起消息的丢失 xff1a 1 生产者发送消息到MQ xf

随机推荐