|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
各位大佬好,我有个问题,在使用panedwindow组件时,修改窗口大小调用sash_place程序会陷入死循环,有什么方法可以解决呢
def adjust_windows(event):
global Win_height
global Win_width
if (Win_height !=ws.winfo_height()) or (Win_width !=ws.winfo_width()):
heightRadio , widthRadio= ws.winfo_height()/Win_height , ws.winfo_width()/Win_width
print(event.type)
pw1.sash_place(1,int(900*widthRadio),0)#放置中间的空间分割线
#pw1.update()
return
可以尝试在 sash_place 函数调用后加上 pw1.update() 来更新组件。这样可以结束当前事件处理,避免死循环。
例如:
- def adjust_windows(event):
- global Win_height
- global Win_width
- if (Win_height !=ws.winfo_height()) or (Win_width !=ws.winfo_width()):
- heightRadio , widthRadio= ws.winfo_height()/Win_height , ws.winfo_width()/Win_width
- print(event.type)
- pw1.sash_place(1,int(900*widthRadio),0)#放置中间的空间分割线
- pw1.update() # 更新组件
- return
复制代码
还可以尝试使用 pw1.unbind('<Configure>') 方法解除绑定事件,在调用 sash_place 函数后再绑定回去。这样也可以避免死循环。
例如:
- def adjust_windows(event):
- global Win_height
- global Win_width
- if (Win_height !=ws.winfo_height()) or (Win_width !=ws.winfo_width()):
- heightRadio , widthRadio= ws.winfo_height()/Win_height , ws.winfo_width()/Win_width
- print(event.type)
- pw1.unbind('<Configure>') # 解除绑定
- pw1.sash_place(1,int(900*widthRadio),0)#放置中间的空间分割线
- pw1.bind('<Configure>', adjust_windows) # 重新绑定
- return
复制代码
|
|