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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
| #!/usr/bin/python
# -*- coding: utf-8 -*-
import Tkinter as tk
def quelletouche(event):
global touche
touche=event
def veriftouche():
w = touche.widget
if touche.char in "0123456789" or touche.keysym == "BackSpace":
if touche.keysym == "BackSpace":
t = ""
else:
t = touche.char
if int("%s%s" % (w.get(), t)) > 255:
return False
return True
w.configure(validate='key', vcmd=veriftouche)
return False
def connectclick():
if connect.cget('text') == "Connect":
connect.config(text="Disconnect")
# Code de connexion
print("Connexion %s.%s.%s.%s" % (e1.get(), e2.get(),
e3.get(), e4.get()))
else:
connect.config(text="Connect")
# Code de deconnexion
print("Deconnexion %s.%s.%s.%s" % (e1.get(), e2.get(),
e3.get(), e4.get()))
root = tk.Tk()
ip = tk.Frame(root, bd=1, relief="sunken")
e1 = tk.Entry(ip, justify="center", bd=0, highlightthickness=0,
insertborderwidth=0, width=5, bg="white")
e1.pack(side="left")
e1.configure(validate='key', vcmd=veriftouche)
e1.bind("<Key>", quelletouche)
tk.Label(ip, text=".", bg="white", bd=0,
highlightthickness=0).pack(side="left")
e2 = tk.Entry(ip, justify="center", bd=0, highlightthickness=0,
insertborderwidth=0, width=5, bg="white")
e2.pack(side="left")
e2.configure(validate='key', vcmd=veriftouche)
e2.bind("<Key>", quelletouche)
tk.Label(ip, text=".", bg="white", bd=0,
highlightthickness=0).pack(side="left")
e3 = tk.Entry(ip, justify="center", bd=0, highlightthickness=0,
insertborderwidth=0, width=5, bg="white")
e3.pack(side="left")
e3.configure(validate='key', vcmd=veriftouche)
e3.bind("<Key>", quelletouche)
tk.Label(ip, text=".", bg="white", bd=0,
highlightthickness=0).pack(side="left")
e4 = tk.Entry(ip, justify="center", bd=0, highlightthickness=0,
insertborderwidth=0, width=5, bg="white")
e4.pack(side="left")
e4.configure(validate='key', vcmd=veriftouche)
e4.bind("<Key>", quelletouche)
connect = tk.Button(ip, text="Connect", command=connectclick, bd=0)
connect.pack(side="left")
ip.pack(side="left")
root.mainloop() |
Partager