tkinter开发:用bind给各个button绑定功能,遇到一些问题
各位大侠好,小弟在 tkinter 开发中又遇到了一个问题,还希望各位大侠鼎力相助,谢谢!
GUI 界面上有很多 button, 想用 bind 将 button 绑定功能:鼠标移动到 button 上能够提示此 button 的功能。功能已经实现,但遇到一个问题:当一个 button 的功能提示框显示出来以后,并且是重叠在另外一个 button 上时,点击 ok 关闭提示框后,另外一个 button 的功能提示框会接着显示出来,不知道这个怎么弄?还望各位大侠帮忙,谢谢!
代码如下:
gui 界面:
logContinueButton=tk.Button(commonRow2Frame,text=”LOG Continue”,width=12,command=AdbCmdImpl.adbCmdLogContinue) logContinueButton.pack(side=tk.LEFT,fill=tk.X,padx=2,pady=3)
logContinueButton.bind(““,func=lambda buttonIndex: ShowButtonTip.showButtonFunctionInfo(buttonIndex,buttonConst.LOG_CONTINUE_BUTTON))
DPEnableButton=tk.Button(commonRow2Frame,text=”Debug Parser En”,command=AdbCmdImpl.adbCmdDPEnable) DPEnableButton.pack(side=tk.LEFT,fill=tk.X,padx=1,pady=3)
DPEnableButton.bind(““,func=lambda buttonIndex: ShowButtonTip.showButtonFunctionInfo(buttonIndex,buttonConst.DP_ENABLE_BUTTON))
….
类似定义了很多 button, 并且都用 bind 绑定了提示框函数
showButtonTip.py
“ “
def showButtonFunctionInfo(self,buttonIndex):
if buttonIndex== buttonConst.LOG_CONTINUE_BUTTON:
message=”aaaa”
elif buttonIndex== buttonConst.DP_ENABLE_BUTTON:
message = “bbbb”
…..
time.sleep(2)
tk.messagebox.showinfo (“功能介绍”,messages)
你问题的代码太乱了,``` python 前要记得多空一行。事件内容都不见了 …
showButtonTip.py
如果是个模块,而ShowButtonTip
是个类的实例showButtonFunctionInfo
方法有两个参数,定义中,扣掉self
不算,只有一个参数.有关工具提示,以下的代码来自 PySimpleGUI, 仅供参考
另外 1 楼不知道在说什么 … 没头没尾的.