微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

当我切换到 PC 中的另一个应用程序时,我的 tkinter 应用程序不会停留或消失

如何解决当我切换到 PC 中的另一个应用程序时,我的 tkinter 应用程序不会停留或消失

当我切换到其他应用程序时,应用程序不会停留在后台。我希望编码人员能更快回复。但如果我将其最小化,它会很好地工作。

我的错误可能是什么,或者可能的解决方案是什么。

import tkinter as tk
root = tk.Tk() 
root.geometry("400x400")
root.overrideredirect(1)
root.resizable(False,False)


def close():
    root.destroy()

def minimizeWindow():
    root.withdraw()
    root.overrideredirect(False)
    root.iconify()

def check_map(event): # apply override on deiconify.
    if str(event) == "<Map event>":
        root.overrideredirect(1)
        print ('Deiconified',event)
    else:
        print ('Iconified',event)

bar_frame = tk.Frame(root)
bar_frame.grid(row=0,column=0,sticky="ew")
bar_frame.columnconfigure(0,weight=1)
# This appears to have the same results so not sure what the difference is from iconbitmap.
# root.tk.call('wm','iconphoto',root._w,icon) 

tk.Button(bar_frame,text='x',command=close).grid(row=0,column=1)
tk.Button(bar_frame,text='-',command=minimizeWindow).grid(row=0,column=2)

root.bind('<Map>',check_map) # added bindings to pass windows status to function
root.bind('<Unmap>',check_map)

import mouse
wy=0
ex=0

def standard_bind():
   root.bind('<B1-Motion>',lambda e: event(e,Mode=True))

def event(widget,Mode=False):
    global ex,wy
    if Mode:
        ex = widget.x
        wy = widget.y
    root.bind('<B1-Motion>',lambda e: event(e))
    root.geometry('+%d+%d' % (mouse.get_position()[0]-ex,mouse.get_position()[1]-wy))
root.bind('<B1-Motion>',Mode=True))
root.bind('<ButtonRelease-1>',lambda e: standard_bind())

root.mainloop()

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。