这很难解释。在我的程序中有两个Checkbutton(这可能是它们的名字,但是我说的是可以标记的正方形)。我希望当鼠标放在它们身上时出现一个小标题。如果我能在消息出现之前设置一个时间,那就更好了。 谢谢你
from tkinter import*
from tkinter import messagebox
root = Tk()
root.configure(bg='lightblue')
root.title("#1")
root.geometry("180x60+350+220")
request = StringVar() #i did the same with all other variables
inte=["explorer" , "Explorer","rete"]
chro=["chrome" ,"Chrome","ricerca",]
of=["openoffice","foglio bianco","scrittura"]
dia = Entry(root, textvariable = request, bg="white").grid(row=0,column=1)
chk = Checkbutton(root,text="Ricerca in internet", textvariable = fla,
bg="lightblue").grid(row=0,column=0) #first checkbutton
chk1 = Checkbutton(root,text="Ricerca in internet", textvariable = ran,
bg="lightblue").grid(row=0,column=2) #the second one
def apri():
if request.get().strip() in inte:
subprocess.Popen(['C:\Program Files\Internet Explorer\\iexplore.exe']) #i did the same with all other lists
else:
webbrowser.open("https://www.google.it/search?q={0}&oq={0}&aqs=chrome..69i57j0j69i61j0l3.1306j0j7&sourceid=chrome&ie=UTF-8".format(request.get().strip()))
bott = Button(root, text="Cerca", command = apri,
bg="white").grid(row=1,column=1)
这是我的程序,我从任何一个步骤中取一个例子
下面的代码将实现您想要的:
现在我们来分解一下
我们使用
.bind("<Enter>", *callback*)
和.bind("<Leave>", *callback*)
分别在鼠标进入或离开小部件的边界框时创建回调然后创建两个回调
enter()
和leave()
。在
enter()
中,我们执行以下操作:1)创建
Toplevel
小部件2)使用
wm_overrideredirect()
,我们实际上只使用它来防止窗口有顶部栏和边框3)设置车窗位置
4)创建一个包
Label
小部件到Toplevel
。我们来分解第三步
所以我们要创建一个几何值,相当于
+n1+n2
,其中n1
和n2
是两个独立的数字(可以相同),其中n1
是x坐标,n2
是y坐标。为了得到x坐标,我们将以下各项相加:在
root
上使用时.winfo_rootx()
的值,它返回屏幕上根窗口的x坐标在
check
上使用时.winfo_x()
的值,返回小部件左边缘相对于根窗口的x坐标在
check
上使用时.winfo_width()
的值,返回小部件的宽度这三个值使窗口左侧的x坐标等于小部件的右边缘,而不管它在哪里绘制,窗口在哪里。
为了得到y坐标,我们将以下各项相加:
在
root
上使用时.winfo_rooty()
的值,它返回屏幕上根窗口的y坐标在
check
上使用时.winfo_y()
的值,返回小部件上边缘相对于根窗口的y坐标这两个值将窗口顶边的y坐标放置在与小部件顶边相等的位置,而不管它绘制在何处以及窗口位于何处。
leave()
要简单得多,当我们调用它时,我们只需销毁Toplevel
小部件相关问题 更多 >
编程相关推荐