-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
script.py
64 lines (50 loc) · 1.81 KB
/
script.py
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
# This is a snake game made with Python Tkinter Library.
#!/usr/bin/python
# Simple button demo.
from Tkinter import *
import socket
# A better way is to create our fancy button by extending the Button class.
class HostnameLabel(Label):
'''A Label widget which knows about an associated Entry widget, and can
look up the host name it contains and display the corresponding IP'''
# Look up host name in the assocated entry widget source, and display
# in ourselves.
def show(self):
hn = self.source.get().strip()
if hn == '':
ip = ''
else:
try:
ip = socket.gethostbyname(hn)
except:
ip = '[unknown]'
self.configure(text=ip)
def __init__(self, root, entry):
Label.__init__(self, root, text="", width=15)
self.source = entry
# Here are the colors. These are just ordinary variables, and I need to
# remember to send them to all relevant widgets.
bgcolor = '#AAAAFF'
actbgcolor = '#CCCCFF'
fgcolor = '#884400'
# Root and backing frame.
root = Tk()
fr = Frame(root, background=bgcolor)
fr.pack()
# Title label
tit = Label(fr, text="Host Name Lookup", background=bgcolor,
foreground=fgcolor, relief='groove')
tit.grid(row=0, column=0, columnspan=2, sticky='news')
# Name entry.
entr = Entry(fr, width=25, background=bgcolor, foreground=fgcolor)
entr.grid(row=1, column=0, columnspan=2, sticky='news')
# Reporting label.
dislab = HostnameLabel(fr, entr)
dislab.configure(background=bgcolor, foreground=fgcolor)
dislab.grid(row=2, column=0, sticky='news')
# Go button.
but = Button(fr, text="Find", background=bgcolor, activebackground=actbgcolor,
foreground=fgcolor, command=dislab.show)
but.grid(row=2, column=1, sticky='news')
root.mainloop()
# End of the program