当我切换到 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 (将#修改为@)