Bonjour,
J ai une question de debutant, j ai besoin de creer une fenetre mais quand je fais
Import wx
Il me dit qu il ne connait pas.
Je suis sous ubuntu, est ce qu il faut faire un truc particulier?
Merci
Version imprimable
Bonjour,
J ai une question de debutant, j ai besoin de creer une fenetre mais quand je fais
Import wx
Il me dit qu il ne connait pas.
Je suis sous ubuntu, est ce qu il faut faire un truc particulier?
Merci
Bonjour,
Tu a installer le paquet python-wxgtk ?
@+
Autre chose : y'a pas sous Python 3
Quelle est l alternative a wxpython pour python3?
En fait je dois faire une tache qui s execute en boucle et qui va pinguer un serveur.
Si celui ci ne repond pas, je dois ouvrir une popup
Merci
Bonsoir,
Est ce vraiment la vrais question ? Pourquoi ne pas utiliser l'existant ?
Qu'avez vous d'installer sur le serveur ? Quelle version de Python ? Quel GUI ?
Sous Ubuntu (de base) vous n'avez pas de Wrapper GUI installé de base.
Si c'est juste pour un popup je pense à Tkinter (Pas du Xdialog quand même... Même pas d'origine sous Ubuntu).
Le code d'import suivant est compatible Python 2/3
Et vous utilisez Tkinter avec 'Tk'Code:
1
2
3
4
5
6
7
8 # -*- coding: utf-8 -*- # # # try: import Tkinter as Tk except: import tkinter as Tk
Au niveau GUI c'est largement suffisant pour ce que vous voulez faire.Code:root = Tk.Tk()
Vous devez bien sur installer python-tk pour Python 2.x ou python3-tk pour Python 3.x.
Maintenant votre projet:
C'est juste un script qui se lance ou un deamon ?
Si c'est un deamon avez vous penser sur quel screen cela vas s'afficher ?
Pensez y
@+
C est plutot un daemon qui me faut et il faudrait que ca tourne sous windows aussi comme service.
Donc est ce qu il est possible a partir de mon .py d inclure toutes les dependances necessaires pour que ca tourne sans rien installer sur les machines client qui auront ca.
Pour pinguer, je pensais utiliser subprocess.popen(ping ip) et ca avec un thread et timer pour qu il tourne en boucle.
Seulement commentnrecuperer si le ping c est bien passe ou non a chaque appel?
Et si ca ne repond pas, ouvrir ma popup.
Merci
Bonjour,
En plus simple
+ ceciCode:
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 # -*- coding: utf-8 -*- # # # import subprocess try: import Tkinter as Tk except: import tkinter as Tk host = '192.168.1.1' def showroot(): root.deiconify() def pingme(): ping = subprocess.Popen(['ping', '-c', '1', host], stdout=subprocess.PIPE) stdo = ping.communicate() if '1 errors' in stdo[0]: showroot() else: root.after(1, pingme) def hideme(): root.withdraw() pingme() root = Tk.Tk() root.title('Information connexion') Tk.Label(root, text="Connexion perdue avec l'hote %s" % host, fg='red').pack(padx=5, pady=5) Tk.Button(root, text='Attendre', command=hideme).pack(side=Tk.LEFT, padx=5, pady=5) Tk.Button(root, text='Quitter', command=root.quit).pack(side=Tk.RIGHT, padx=5, pady=5) hideme() root.mainloop()
@+
Re,
Maintenant si c'est 'pour ne rien installer' vous pouvez le faire avec wx.
Qu'importe la version de Python ?
Petit oubli, la version wx (code a corriger)
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
35
36
37
38
39
40
41 import wx import subprocess class Frame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, title="Information connexion", size=(300,100)) self.st = wx.StaticText(self, 1, "Connexion perdue avec l'hote %s" % host, (5,30)) self.st.SetForegroundColour(wx.RED) wx.Button(self, 2, 'Quitter', (150, 60)) wx.Button(self, 3, 'Attendre', (50, 60)) self.Bind(wx.EVT_BUTTON, self.OnCloseWindow, id=2) self.Bind(wx.EVT_BUTTON, self.ReStart, id=3) self.timer = wx.Timer(self) self.timer.Start(1) self.Bind(wx.EVT_TIMER, self.Cycle) self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) def OnCloseWindow(self, evt): self.timer.Stop() del self.timer self.Destroy() def ShowRoot(self): self.timer.Stop() frm.Show() def ReStart(self, evt): self.Hide() self.timer.Start(1) def Cycle(self, evt): ping = subprocess.Popen(['ping', '-c', '1', host], stdout=subprocess.PIPE) stdo = ping.communicate() if '1 errors' in stdo[0]: self.ShowRoot() host = '192.168.1.1' app = wx.App(False) frm = Frame() frm.Centre() app.MainLoop()