【问题标题】:How to make message appear next to mouse when hovering over a entry box or image?将鼠标悬停在输入框或图像上时,如何使消息出现在鼠标旁边?
【发布时间】:2021-02-03 12:23:35
【问题描述】:

我设计了一个带有登录屏幕的 GUI。当用户的鼠标悬停在文本框或角落的徽标上时,我希望鼠标旁边出现一条小消息,以告知用户它是什么或它的用途。

我问了一个朋友,但他只知道如何用 HTML 来做,而我正在使用 python。这种效果是否可能,如果可以,我需要包含哪些代码?

Here is an example of the effect I mean.

如果有人想编辑,我已经包含了一些代码。

from tkinter import *

temp = Tk()
temp.geometry('500x300')
temp.title("Login Screen")

logo = PhotoImage(file='image.png')
logoplace = Label(temp, image=logo, bg='black')
logoplace.pack()

Entrybox = Entry(temp, width=20)
Entrybox.pack()

temp.mainloop()

【问题讨论】:

标签: python tkinter hover tkinter-entry


【解决方案1】:
import tkinter as tk
import webbrowser

from idlelib.tooltip import Hovertip
root = tk.Tk()
root.title('Hover')
canvas = tk.Canvas(root, bg='gray')
canvas.pack()
def Hover():
 url = 'https://stackoverflow.com'
 webbrowser.open_new(url)
myBtn = tk.Button(canvas,command=Hover,text='My Button',bg='black', fg='white')
myBtn.pack(padx=(100))
myBtn.pack(pady=(100))
myTip = Hovertip(myBtn,'Hello World!')
root.mainloop()

Example

【讨论】:

    猜你喜欢
    • 2012-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-09
    • 1970-01-01
    • 1970-01-01
    • 2020-11-27
    • 1970-01-01
    相关资源
    最近更新 更多