Bonjour,
je voudrais afficher une boîte de dialogue où se trouve un lien cliquable vers un site HTML. Est-ce possible ?
Version imprimable
Bonjour,
je voudrais afficher une boîte de dialogue où se trouve un lien cliquable vers un site HTML. Est-ce possible ?
Bonjour,
C'est possible, en utilisant le module webbrowser.
Ex :
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 from Tkinter import * import webbrowser class MyDialog(Toplevel): def __init__(self, parent, titre, texte, url): Toplevel.__init__(self, parent) self.transient(parent) self.lien=Label(self, text=texte) self.lien.pack(pady=10) self.url=url self.lien.bind("<Enter>", self._enter) self.lien.bind("<Leave>", self._leave) self.lien.bind("<Button-1>", self._click) Button(self,text='OK', width=5, command=self.destroy).pack() self.focus_set() self.grab_set() #intercepte les events def _enter(self, event): self.lien.config(cursor="hand2") def _leave(self, event): self.lien.config(cursor="") def _click(self, event): webbrowser.open(self.url) if __name__=="__main__": def affiche_dialog(): d=MyDialog(root, titre="Dialogue avec html", texte="Un lien utile", url="http://python.developpez.com/faq/") root=Tk() Button(root, text="Afficher dialog", command=affiche_dialog).pack() root.mainloop()
Merci pour cette réponse rapide et qui marche très bien.